clock.h revision 95154
1135446Strhodes/*
2234010Sdougb * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
3135446Strhodes *	All rights reserved.
4135446Strhodes * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5193149Sdougb * Copyright (c) 1988, 1993
6135446Strhodes *	The Regents of the University of California.  All rights reserved.
7135446Strhodes *
8135446Strhodes * By using this file, you agree to the terms and conditions set
9135446Strhodes * forth in the LICENSE file which can be found at the top level of
10135446Strhodes * the sendmail distribution.
11135446Strhodes *
12135446Strhodes *	$Id: clock.h,v 1.1.1.1 2002/02/17 21:56:43 gshapiro Exp $
13135446Strhodes */
14135446Strhodes
15135446Strhodes/*
16135446Strhodes**  CLOCK.H -- for co-ordinating timed events
17135446Strhodes*/
18234010Sdougb
19135446Strhodes#ifndef _SM_CLOCK_H
20135446Strhodes# define _SM_CLOCK_H 1
21135446Strhodes
22135446Strhodes# include <sm/signal.h>
23135446Strhodes# if SM_CONF_SETITIMER
24135446Strhodes#  include <sys/time.h>
25135446Strhodes# endif /* SM_CONF_SETITIMER */
26135446Strhodes
27193149Sdougb/*
28170222Sdougb**  STRUCT SM_EVENT -- event queue.
29135446Strhodes**
30135446Strhodes**	Maintained in sorted order.
31135446Strhodes**
32135446Strhodes**	We store the pid of the process that set this event to insure
33135446Strhodes**	that when we fork we will not take events intended for the parent.
34135446Strhodes*/
35135446Strhodes
36170222Sdougbstruct sm_event
37135446Strhodes{
38135446Strhodes# if SM_CONF_SETITIMER
39170222Sdougb	struct timeval	ev_time;	/* time of the call (microseconds) */
40135446Strhodes# else /* SM_CONF_SETITIMER */
41135446Strhodes	time_t		ev_time;	/* time of the call (seconds) */
42170222Sdougb# endif /* SM_CONF_SETITIMER */
43135446Strhodes	void		(*ev_func)__P((int));
44135446Strhodes					/* function to call */
45170222Sdougb	int		ev_arg;		/* argument to ev_func */
46135446Strhodes	pid_t		ev_pid;		/* pid that set this event */
47135446Strhodes	struct sm_event	*ev_link;	/* link to next item */
48170222Sdougb};
49135446Strhodes
50135446Strhodestypedef struct sm_event	SM_EVENT;
51170222Sdougb
52135446Strhodes/* functions */
53135446Strhodesextern void	sm_clrevent __P((SM_EVENT *));
54135446Strhodesextern void	sm_clear_events __P((void));
55135446Strhodesextern SM_EVENT	*sm_setevent __P((time_t, void(*)(), int));
56170222Sdougbextern SM_EVENT	*sm_seteventm __P((int, void(*)(), int));
57135446Strhodesextern SM_EVENT	*sm_sigsafe_seteventm __P((int, void(*)(), int));
58135446Strhodesextern SIGFUNC_DECL	sm_tick __P((int));
59245163Serwin
60135446Strhodes/*
61135446Strhodes**  SM_SETEVENT -- set an event to happen at a specific time in seconds.
62135446Strhodes**
63170222Sdougb**	Translates the seconds into millseconds and calls sm_seteventm()
64170222Sdougb**	to get a specific event to happen in the future at a specific time.
65170222Sdougb**
66170222Sdougb**	Parameters:
67170222Sdougb**		t -- intvl until next event occurs (seconds).
68170222Sdougb**		f -- function to call on event.
69135446Strhodes**		a -- argument to func on event.
70135446Strhodes**
71135446Strhodes**	Returns:
72135446Strhodes**		result of sm_seteventm().
73135446Strhodes**
74135446Strhodes**	Side Effects:
75135446Strhodes**		Any that sm_seteventm() have.
76135446Strhodes*/
77135446Strhodes
78135446Strhodes#define sm_setevent(t, f, a) sm_seteventm((int)((t) * 1000), (f), (a))
79135446Strhodes#define sm_sigsafe_setevent(t, f, a) sm_sigsafe_seteventm((int)((t) * 1000), (f), (a))
80135446Strhodes
81135446Strhodes#endif /* _SM_CLOCK_H */
82193149Sdougb