xref: /freebsd/contrib/sendmail/include/sm/clock.h (revision 4026605903c0ab8df33c4ae8c419acdb2b652af8)
140266059SGregory Neil Shapiro /*
240266059SGregory Neil Shapiro  * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
340266059SGregory Neil Shapiro  *	All rights reserved.
440266059SGregory Neil Shapiro  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
540266059SGregory Neil Shapiro  * Copyright (c) 1988, 1993
640266059SGregory Neil Shapiro  *	The Regents of the University of California.  All rights reserved.
740266059SGregory Neil Shapiro  *
840266059SGregory Neil Shapiro  * By using this file, you agree to the terms and conditions set
940266059SGregory Neil Shapiro  * forth in the LICENSE file which can be found at the top level of
1040266059SGregory Neil Shapiro  * the sendmail distribution.
1140266059SGregory Neil Shapiro  *
1240266059SGregory Neil Shapiro  *	$Id: clock.h,v 1.11 2001/05/14 23:25:37 gshapiro Exp $
1340266059SGregory Neil Shapiro  */
1440266059SGregory Neil Shapiro 
1540266059SGregory Neil Shapiro /*
1640266059SGregory Neil Shapiro **  CLOCK.H -- for co-ordinating timed events
1740266059SGregory Neil Shapiro */
1840266059SGregory Neil Shapiro 
1940266059SGregory Neil Shapiro #ifndef _SM_CLOCK_H
2040266059SGregory Neil Shapiro # define _SM_CLOCK_H 1
2140266059SGregory Neil Shapiro 
2240266059SGregory Neil Shapiro # include <sm/signal.h>
2340266059SGregory Neil Shapiro # if SM_CONF_SETITIMER
2440266059SGregory Neil Shapiro #  include <sys/time.h>
2540266059SGregory Neil Shapiro # endif /* SM_CONF_SETITIMER */
2640266059SGregory Neil Shapiro 
2740266059SGregory Neil Shapiro /*
2840266059SGregory Neil Shapiro **  STRUCT SM_EVENT -- event queue.
2940266059SGregory Neil Shapiro **
3040266059SGregory Neil Shapiro **	Maintained in sorted order.
3140266059SGregory Neil Shapiro **
3240266059SGregory Neil Shapiro **	We store the pid of the process that set this event to insure
3340266059SGregory Neil Shapiro **	that when we fork we will not take events intended for the parent.
3440266059SGregory Neil Shapiro */
3540266059SGregory Neil Shapiro 
3640266059SGregory Neil Shapiro struct sm_event
3740266059SGregory Neil Shapiro {
3840266059SGregory Neil Shapiro # if SM_CONF_SETITIMER
3940266059SGregory Neil Shapiro 	struct timeval	ev_time;	/* time of the call (microseconds) */
4040266059SGregory Neil Shapiro # else /* SM_CONF_SETITIMER */
4140266059SGregory Neil Shapiro 	time_t		ev_time;	/* time of the call (seconds) */
4240266059SGregory Neil Shapiro # endif /* SM_CONF_SETITIMER */
4340266059SGregory Neil Shapiro 	void		(*ev_func)__P((int));
4440266059SGregory Neil Shapiro 					/* function to call */
4540266059SGregory Neil Shapiro 	int		ev_arg;		/* argument to ev_func */
4640266059SGregory Neil Shapiro 	pid_t		ev_pid;		/* pid that set this event */
4740266059SGregory Neil Shapiro 	struct sm_event	*ev_link;	/* link to next item */
4840266059SGregory Neil Shapiro };
4940266059SGregory Neil Shapiro 
5040266059SGregory Neil Shapiro typedef struct sm_event	SM_EVENT;
5140266059SGregory Neil Shapiro 
5240266059SGregory Neil Shapiro /* functions */
5340266059SGregory Neil Shapiro extern void	sm_clrevent __P((SM_EVENT *));
5440266059SGregory Neil Shapiro extern void	sm_clear_events __P((void));
5540266059SGregory Neil Shapiro extern SM_EVENT	*sm_setevent __P((time_t, void(*)(), int));
5640266059SGregory Neil Shapiro extern SM_EVENT	*sm_seteventm __P((int, void(*)(), int));
5740266059SGregory Neil Shapiro extern SM_EVENT	*sm_sigsafe_seteventm __P((int, void(*)(), int));
5840266059SGregory Neil Shapiro extern SIGFUNC_DECL	sm_tick __P((int));
5940266059SGregory Neil Shapiro 
6040266059SGregory Neil Shapiro /*
6140266059SGregory Neil Shapiro **  SM_SETEVENT -- set an event to happen at a specific time in seconds.
6240266059SGregory Neil Shapiro **
6340266059SGregory Neil Shapiro **	Translates the seconds into millseconds and calls sm_seteventm()
6440266059SGregory Neil Shapiro **	to get a specific event to happen in the future at a specific time.
6540266059SGregory Neil Shapiro **
6640266059SGregory Neil Shapiro **	Parameters:
6740266059SGregory Neil Shapiro **		t -- intvl until next event occurs (seconds).
6840266059SGregory Neil Shapiro **		f -- function to call on event.
6940266059SGregory Neil Shapiro **		a -- argument to func on event.
7040266059SGregory Neil Shapiro **
7140266059SGregory Neil Shapiro **	Returns:
7240266059SGregory Neil Shapiro **		result of sm_seteventm().
7340266059SGregory Neil Shapiro **
7440266059SGregory Neil Shapiro **	Side Effects:
7540266059SGregory Neil Shapiro **		Any that sm_seteventm() have.
7640266059SGregory Neil Shapiro */
7740266059SGregory Neil Shapiro 
7840266059SGregory Neil Shapiro #define sm_setevent(t, f, a) sm_seteventm((int)((t) * 1000), (f), (a))
7940266059SGregory Neil Shapiro #define sm_sigsafe_setevent(t, f, a) sm_sigsafe_seteventm((int)((t) * 1000), (f), (a))
8040266059SGregory Neil Shapiro 
8140266059SGregory Neil Shapiro #endif /* _SM_CLOCK_H */
82