]>
git.saurik.com Git - apple/ipsec.git/blob - ipsec-tools/racoon/schedule.c
1 /* $NetBSD: schedule.c,v 1.4 2006/09/09 16:22:10 manu Exp $ */
3 /* $KAME: schedule.c,v 1.19 2001/11/05 10:53:19 sakane Exp $ */
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/types.h>
37 #include <sys/param.h>
39 #include <sys/queue.h>
40 #include <sys/socket.h>
47 #include <dispatch/dispatch.h>
54 #include "power_mgmt.h"
55 #include "localconf.h"
57 #if !defined(__LP64__)
58 // year 2038 problem and fix for 32-bit only
59 #define FIXY2038PROBLEM
63 extern int terminated
;
65 #ifdef FIXY2038PROBLEM
66 #define Y2038TIME_T 0x7fffffff
67 static time_t launched
; /* time when the program launched. */
68 static time_t deltaY2038
;
71 static TAILQ_HEAD(_schedtree
, sched
) sctree
;
75 timer_handler(struct sched
*sched
)
77 if (slept_at
|| woke_at
)
80 TAILQ_REMOVE(&sctree
, sched
, chain
);
83 if (sched
->func
!= NULL
&& !terminated
) {
84 (sched
->func
)(sched
->param
);
91 * add new schedule to schedule table.
94 sched_new(time_t tick
, void (*func
) (void *), void *param
)
96 static schedule_ref next_ref
= 1;
97 struct sched
*new_sched
;
102 new_sched
= (struct sched
*)racoon_malloc(sizeof(*new_sched
));
103 if (new_sched
== NULL
)
106 new_sched
->ref
= next_ref
++;
108 new_sched
->func
= func
;
109 new_sched
->param
= param
;
110 new_sched
->xtime
= current_time() + tick
;
112 /* add to schedule table */
113 TAILQ_INSERT_TAIL(&sctree
, new_sched
, chain
);
114 dispatch_after(dispatch_time(DISPATCH_TIME_NOW
, tick
* NSEC_PER_SEC
), dispatch_get_main_queue(),
116 timer_handler(new_sched
);
119 return new_sched
->ref
;
123 * if defined FIXY2038PROBLEM, base time is the time when called sched_init().
124 * Otherwise, conform to time(3).
130 #ifdef FIXY2038PROBLEM
145 sched_is_dead(schedule_ref ref
)
151 TAILQ_FOREACH(sc
, &sctree
, chain
) {
152 if (sc
->ref
== ref
) {
163 sched_get_time(schedule_ref ref
, time_t *time
)
168 TAILQ_FOREACH(sc
, &sctree
, chain
) {
169 if (sc
->ref
== ref
) {
181 sched_kill(schedule_ref ref
)
186 TAILQ_FOREACH(sc
, &sctree
, chain
) {
187 if (sc
->ref
== ref
) {
200 TAILQ_FOREACH(sc
, &sctree
, chain
)
205 /* XXX this function is probably unnecessary. */
207 sched_scrub_param(void *param
)
211 TAILQ_FOREACH(sc
, &sctree
, chain
) {
212 if (sc
->param
== param
) {
218 /* initialize schedule table */
222 #ifdef FIXY2038PROBLEM
225 deltaY2038
= Y2038TIME_T
- launched
;