1 /* $NetBSD: schedule.h,v 1.7 2009/01/23 08:25:07 tteras Exp $ */
3 /* Id: schedule.h,v 1.5 2006/05/03 21:53:42 vanhu Exp */
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Copyright (C) 2008 Timo Teras.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
40 #include <sys/queue.h>
41 #if TIME_WITH_SYS_TIME
42 # include <sys/time.h>
46 # include <sys/time.h>
54 #ifdef __compiler_offsetof
55 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
57 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
62 #define container_of(ptr, type, member) ({ \
63 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
64 (type *)( (char *)__mptr - offsetof(type,member) );})
68 /* scheduling table */
69 /* the head is the nearest event. */
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 */
78 #define SCHED_INITIALIZER() { NULL, }
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
));
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
*));
96 int sched_dump
__P((caddr_t
*, int *));
97 void sched_init
__P((void));
99 #endif /* _SCHEDULE_H */