xref: /netbsd-src/crypto/dist/ipsec-tools/src/racoon/schedule.h (revision 82dd0659f27bc1f93d5ad7cb1a12720aadf99441)
1 /*	$NetBSD: schedule.h,v 1.8 2009/08/17 12:00:53 vanhu Exp $	*/
2 
3 /* Id: schedule.h,v 1.5 2006/05/03 21:53:42 vanhu Exp */
4 
5 /*
6  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7  * Copyright (C) 2008 Timo Teras.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the project nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #ifndef _SCHEDULE_H
36 #define _SCHEDULE_H
37 
38 #include <stddef.h>
39 
40 #include <sys/queue.h>
41 #if TIME_WITH_SYS_TIME
42 # include <sys/time.h>
43 # include <time.h>
44 #else
45 # if HAVE_SYS_TIME_H
46 #  include <sys/time.h>
47 # else
48 #  include <time.h>
49 # endif
50 #endif
51 #include "gnuc.h"
52 
53 #ifndef offsetof
54 #ifdef __compiler_offsetof
55 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
56 #else
57 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
58 #endif
59 #endif
60 
61 #ifndef container_of
62 #define container_of(ptr, type, member) ({                      \
63         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
64         (type *)( (char *)__mptr - offsetof(type,member) );})
65 #endif
66 
67 
68 /* scheduling table */
69 /* the head is the nearest event. */
70 struct sched {
71 	void (*func) __P((struct sched *));	/* callback on timeout */
72 	struct timeval xtime;			/* expiration time */
73 	struct timeval tick;			/* relative timeout */
74 	TAILQ_ENTRY(sched) chain;
75 	long id;				/* for debug */
76 };
77 
78 #define SCHED_INITIALIZER() { NULL, }
79 
80 struct scheddump {
81 	time_t xtime;
82 	long id;
83 	time_t created;
84 	time_t tick;
85 };
86 
87 time_t sched_monotonic_to_time_t __P((struct timeval *tv,
88 				      struct timeval *now));
89 void sched_get_monotonic_time __P((struct timeval *tv));
90 
91 struct timeval *schedular __P((void));
92 void sched_schedule __P((struct sched *, time_t,
93 			 void (*func) __P((struct sched *))));
94 void sched_cancel __P((struct sched *));
95 
96 int sched_dump __P((caddr_t *, int *));
97 void sched_init __P((void));
98 
99 #endif /* _SCHEDULE_H */
100