worldstone: add -s for statistical profiling
[minix.git] / lib / libtimers / tmrs_set.c
blob71e56a9f59cc9c14d726789a766a593b19f68b62
1 #include "timers.h"
3 /*===========================================================================*
4 * tmrs_settimer *
5 *===========================================================================*/
6 clock_t tmrs_settimer(tmrs, tp, exp_time, watchdog, new_head)
7 timer_t **tmrs; /* pointer to timers queue */
8 timer_t *tp; /* the timer to be added */
9 clock_t exp_time; /* its expiration time */
10 tmr_func_t watchdog; /* watchdog function to be run */
11 clock_t *new_head; /* new earliest timer, if non NULL */
13 /* Activate a timer to run function 'fp' at time 'exp_time'. If the timer is
14 * already in use it is first removed from the timers queue. Then, it is put
15 * in the list of active timers with the first to expire in front.
16 * The caller responsible for scheduling a new alarm for the timer if needed.
18 timer_t **atp;
19 clock_t old_head = 0;
21 if(*tmrs)
22 old_head = (*tmrs)->tmr_exp_time;
24 /* Set the timer's variables. */
25 (void) tmrs_clrtimer(tmrs, tp, NULL);
26 tp->tmr_exp_time = exp_time;
27 tp->tmr_func = watchdog;
29 /* Add the timer to the active timers. The next timer due is in front. */
30 for (atp = tmrs; *atp != NULL; atp = &(*atp)->tmr_next) {
31 if (exp_time < (*atp)->tmr_exp_time) break;
33 tp->tmr_next = *atp;
34 *atp = tp;
35 if(new_head)
36 (*new_head) = (*tmrs)->tmr_exp_time;
37 return old_head;