2 * The mrouted program is covered by the license in the accompanying file
3 * named "LICENSE.mrouted". Use of the mrouted program represents acceptance
4 * of the terms and conditions listed in that file.
6 * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
7 * Leland Stanford Junior University.
10 * callout.c,v 3.8.4.5 1997/05/16 20:18:25 fenner Exp
13 * Questions concerning this software should be directed to
14 * Mickael Hoerdt (hoerdt@clarinet.u-strasbg.fr) LSIIT Strasbourg.
18 * This program has been derived from pim6dd.
19 * The pim6dd program is covered by the license in the accompanying file
20 * named "LICENSE.pim6dd".
23 * This program has been derived from pimd.
24 * The pimd program is covered by the license in the accompanying file
25 * named "LICENSE.pimd".
38 /* the code below implements a callout queue */
41 static struct timeout_q *Q = 0; /* pointer to the beginning of timeout queue */
45 struct timeout_q *next; /* next event */
47 cfunc_t func; /* function to call */
48 void *data; /* func's data */
49 int time; /* time offset to next event */
53 #define CALLOUT_DEBUG 1
54 #define CALLOUT_DEBUG2 1
58 static void print_Q __P((void));
66 Q = (struct timeout_q *) 0;
84 * elapsed_time seconds have passed; perform all the events that should
88 age_callout_queue(elapsed_time)
91 struct timeout_q *ptr,
95 IF_DEBUG(DEBUG_TIMEOUT)
96 log(LOG_DEBUG, 0, "aging queue (elapsed time %d):", elapsed_time);
105 if (Q->time > elapsed_time)
107 Q->time -= elapsed_time;
117 elapsed_time -= Q->time;
123 /* handle queue of expired timers */
128 ptr->func(ptr->data);
135 * Return in how many seconds age_callout_queue() would like to be called.
136 * Return -1 if there are no events pending.
146 log(LOG_WARNING, 0, "timer_nextTimer top of queue says %d",
160 timer_setTimer(delay, action, data)
161 int delay; /* number of units for timeout */
162 cfunc_t action; /* function to be called on timeout */
163 void *data; /* what to call the timeout function with */
165 struct timeout_q *ptr,
170 IF_DEBUG(DEBUG_TIMEOUT)
171 log(LOG_DEBUG, 0, "setting timer:");
177 node = (struct timeout_q *) malloc(sizeof(struct timeout_q));
180 log(LOG_WARNING, 0, "Malloc Failed in timer_settimer\n");
191 /* insert node in the queue */
193 /* if the queue is empty, insert the node and return */
199 /* chase the pointer looking for the right place */
204 if (delay < ptr->time)
213 ptr->time -= node->time;
233 /* returns the time until the timer is scheduled */
236 timer_leftTimer(timer_id)
239 struct timeout_q *ptr;
245 for (ptr = Q; ptr; ptr = ptr->next)
248 if (ptr->id == timer_id)
254 /* clears the associated timer */
257 timer_clearTimer(timer_id)
260 struct timeout_q *ptr,
269 * find the right node, delete it. the subsequent node's time gets bumped
276 if (ptr->id == timer_id)
278 /* got the right node */
280 /* unlink it from the queue */
285 prev->next = ptr->next;
287 /* increment next node if any */
289 (ptr->next)->time += ptr->time;
303 #ifdef CALLOUT_DEBUG2
311 struct timeout_q *ptr;
313 IF_DEBUG(DEBUG_TIMEOUT)
314 for (ptr = Q; ptr; ptr = ptr->next)
315 log(LOG_DEBUG, 0, "(%d,%d) ", ptr->id, ptr->time);
317 #endif /* CALLOUT_DEBUG2 */