1 #include "timers.h" 2 3 /*===========================================================================* 4 * tmrs_settimer * 5 *===========================================================================*/ 6 clock_t tmrs_settimer(tmrs, tp, exp_time, watchdog, new_head) 7 minix_timer_t **tmrs; /* pointer to timers queue */ 8 minix_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 */ 12 { 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. 17 */ 18 minix_timer_t **atp; 19 clock_t old_head = 0; 20 21 if(*tmrs) 22 old_head = (*tmrs)->tmr_exp_time; 23 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; 28 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; 32 } 33 tp->tmr_next = *atp; 34 *atp = tp; 35 if(new_head) 36 (*new_head) = (*tmrs)->tmr_exp_time; 37 return old_head; 38 } 39 40