1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998-2001, 2004 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *	All rights reserved.
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1988, 1993
6*7c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
7*7c478bd9Sstevel@tonic-gate  *
8*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
9*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
10*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
11*7c478bd9Sstevel@tonic-gate  *
12*7c478bd9Sstevel@tonic-gate  *	$Id: clock.h,v 1.12 2004/08/03 19:57:21 ca Exp $
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate /*
18*7c478bd9Sstevel@tonic-gate **  CLOCK.H -- for co-ordinating timed events
19*7c478bd9Sstevel@tonic-gate */
20*7c478bd9Sstevel@tonic-gate 
21*7c478bd9Sstevel@tonic-gate #ifndef _SM_CLOCK_H
22*7c478bd9Sstevel@tonic-gate # define _SM_CLOCK_H 1
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate # include <sm/signal.h>
25*7c478bd9Sstevel@tonic-gate # if SM_CONF_SETITIMER
26*7c478bd9Sstevel@tonic-gate #  include <sys/time.h>
27*7c478bd9Sstevel@tonic-gate # endif /* SM_CONF_SETITIMER */
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate **  STRUCT SM_EVENT -- event queue.
31*7c478bd9Sstevel@tonic-gate **
32*7c478bd9Sstevel@tonic-gate **	Maintained in sorted order.
33*7c478bd9Sstevel@tonic-gate **
34*7c478bd9Sstevel@tonic-gate **	We store the pid of the process that set this event to insure
35*7c478bd9Sstevel@tonic-gate **	that when we fork we will not take events intended for the parent.
36*7c478bd9Sstevel@tonic-gate */
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate struct sm_event
39*7c478bd9Sstevel@tonic-gate {
40*7c478bd9Sstevel@tonic-gate # if SM_CONF_SETITIMER
41*7c478bd9Sstevel@tonic-gate 	struct timeval	ev_time;	/* time of the call (microseconds) */
42*7c478bd9Sstevel@tonic-gate # else /* SM_CONF_SETITIMER */
43*7c478bd9Sstevel@tonic-gate 	time_t		ev_time;	/* time of the call (seconds) */
44*7c478bd9Sstevel@tonic-gate # endif /* SM_CONF_SETITIMER */
45*7c478bd9Sstevel@tonic-gate 	void		(*ev_func)__P((int));
46*7c478bd9Sstevel@tonic-gate 					/* function to call */
47*7c478bd9Sstevel@tonic-gate 	int		ev_arg;		/* argument to ev_func */
48*7c478bd9Sstevel@tonic-gate 	pid_t		ev_pid;		/* pid that set this event */
49*7c478bd9Sstevel@tonic-gate 	struct sm_event	*ev_link;	/* link to next item */
50*7c478bd9Sstevel@tonic-gate };
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate typedef struct sm_event	SM_EVENT;
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /* functions */
55*7c478bd9Sstevel@tonic-gate extern void	sm_clrevent __P((SM_EVENT *));
56*7c478bd9Sstevel@tonic-gate extern void	sm_clear_events __P((void));
57*7c478bd9Sstevel@tonic-gate extern SM_EVENT	*sm_seteventm __P((int, void(*)__P((int)), int));
58*7c478bd9Sstevel@tonic-gate extern SM_EVENT	*sm_sigsafe_seteventm __P((int, void(*)__P((int)), int));
59*7c478bd9Sstevel@tonic-gate extern SIGFUNC_DECL	sm_tick __P((int));
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate **  SM_SETEVENT -- set an event to happen at a specific time in seconds.
63*7c478bd9Sstevel@tonic-gate **
64*7c478bd9Sstevel@tonic-gate **	Translates the seconds into millseconds and calls sm_seteventm()
65*7c478bd9Sstevel@tonic-gate **	to get a specific event to happen in the future at a specific time.
66*7c478bd9Sstevel@tonic-gate **
67*7c478bd9Sstevel@tonic-gate **	Parameters:
68*7c478bd9Sstevel@tonic-gate **		t -- intvl until next event occurs (seconds).
69*7c478bd9Sstevel@tonic-gate **		f -- function to call on event.
70*7c478bd9Sstevel@tonic-gate **		a -- argument to func on event.
71*7c478bd9Sstevel@tonic-gate **
72*7c478bd9Sstevel@tonic-gate **	Returns:
73*7c478bd9Sstevel@tonic-gate **		result of sm_seteventm().
74*7c478bd9Sstevel@tonic-gate **
75*7c478bd9Sstevel@tonic-gate **	Side Effects:
76*7c478bd9Sstevel@tonic-gate **		Any that sm_seteventm() have.
77*7c478bd9Sstevel@tonic-gate */
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate #define sm_setevent(t, f, a) sm_seteventm((int)((t) * 1000), (f), (a))
80*7c478bd9Sstevel@tonic-gate #define sm_sigsafe_setevent(t, f, a) sm_sigsafe_seteventm((int)((t) * 1000), (f), (a))
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate #endif /* _SM_CLOCK_H */
83