aboutsummaryrefslogtreecommitdiff
path: root/sendmail/include/sm/clock.h
blob: ba7fd6891093499613a5055b382daad6f759cef8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright (c) 1998-2001, 2004 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
 * Copyright (c) 1988, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 *
 *	$Id: clock.h,v 1.12 2004/08/03 19:57:21 ca Exp $
 */

/*
**  CLOCK.H -- for co-ordinating timed events
*/

#ifndef _SM_CLOCK_H
# define _SM_CLOCK_H 1

# include <sm/signal.h>
# if SM_CONF_SETITIMER
#  include <sys/time.h>
# endif /* SM_CONF_SETITIMER */

/*
**  STRUCT SM_EVENT -- event queue.
**
**	Maintained in sorted order.
**
**	We store the pid of the process that set this event to insure
**	that when we fork we will not take events intended for the parent.
*/

struct sm_event
{
# if SM_CONF_SETITIMER
	struct timeval	ev_time;	/* time of the call (microseconds) */
# else /* SM_CONF_SETITIMER */
	time_t		ev_time;	/* time of the call (seconds) */
# endif /* SM_CONF_SETITIMER */
	void		(*ev_func)__P((int));
					/* function to call */
	int		ev_arg;		/* argument to ev_func */
	pid_t		ev_pid;		/* pid that set this event */
	struct sm_event	*ev_link;	/* link to next item */
};

typedef struct sm_event	SM_EVENT;

/* functions */
extern void	sm_clrevent __P((SM_EVENT *));
extern void	sm_clear_events __P((void));
extern SM_EVENT	*sm_seteventm __P((int, void(*)__P((int)), int));
extern SM_EVENT	*sm_sigsafe_seteventm __P((int, void(*)__P((int)), int));
extern SIGFUNC_DECL	sm_tick __P((int));

/*
**  SM_SETEVENT -- set an event to happen at a specific time in seconds.
**
**	Translates the seconds into millseconds and calls sm_seteventm()
**	to get a specific event to happen in the future at a specific time.
**
**	Parameters:
**		t -- intvl until next event occurs (seconds).
**		f -- function to call on event.
**		a -- argument to func on event.
**
**	Returns:
**		result of sm_seteventm().
**
**	Side Effects:
**		Any that sm_seteventm() have.
*/

#define sm_setevent(t, f, a) sm_seteventm((int)((t) * 1000), (f), (a))
#define sm_sigsafe_setevent(t, f, a) sm_sigsafe_seteventm((int)((t) * 1000), (f), (a))

#endif /* _SM_CLOCK_H */