1*433d6423SLionel Sambuc #include "timers.h" 2*433d6423SLionel Sambuc 3*433d6423SLionel Sambuc /*===========================================================================* 4*433d6423SLionel Sambuc * tmrs_settimer * 5*433d6423SLionel Sambuc *===========================================================================*/ 6*433d6423SLionel Sambuc clock_t tmrs_settimer(tmrs, tp, exp_time, watchdog, new_head) 7*433d6423SLionel Sambuc minix_timer_t **tmrs; /* pointer to timers queue */ 8*433d6423SLionel Sambuc minix_timer_t *tp; /* the timer to be added */ 9*433d6423SLionel Sambuc clock_t exp_time; /* its expiration time */ 10*433d6423SLionel Sambuc tmr_func_t watchdog; /* watchdog function to be run */ 11*433d6423SLionel Sambuc clock_t *new_head; /* new earliest timer, if non NULL */ 12*433d6423SLionel Sambuc { 13*433d6423SLionel Sambuc /* Activate a timer to run function 'fp' at time 'exp_time'. If the timer is 14*433d6423SLionel Sambuc * already in use it is first removed from the timers queue. Then, it is put 15*433d6423SLionel Sambuc * in the list of active timers with the first to expire in front. 16*433d6423SLionel Sambuc * The caller responsible for scheduling a new alarm for the timer if needed. 17*433d6423SLionel Sambuc */ 18*433d6423SLionel Sambuc minix_timer_t **atp; 19*433d6423SLionel Sambuc clock_t old_head = 0; 20*433d6423SLionel Sambuc 21*433d6423SLionel Sambuc if(*tmrs) 22*433d6423SLionel Sambuc old_head = (*tmrs)->tmr_exp_time; 23*433d6423SLionel Sambuc 24*433d6423SLionel Sambuc /* Set the timer's variables. */ 25*433d6423SLionel Sambuc (void) tmrs_clrtimer(tmrs, tp, NULL); 26*433d6423SLionel Sambuc tp->tmr_exp_time = exp_time; 27*433d6423SLionel Sambuc tp->tmr_func = watchdog; 28*433d6423SLionel Sambuc 29*433d6423SLionel Sambuc /* Add the timer to the active timers. The next timer due is in front. */ 30*433d6423SLionel Sambuc for (atp = tmrs; *atp != NULL; atp = &(*atp)->tmr_next) { 31*433d6423SLionel Sambuc if (exp_time < (*atp)->tmr_exp_time) break; 32*433d6423SLionel Sambuc } 33*433d6423SLionel Sambuc tp->tmr_next = *atp; 34*433d6423SLionel Sambuc *atp = tp; 35*433d6423SLionel Sambuc if(new_head) 36*433d6423SLionel Sambuc (*new_head) = (*tmrs)->tmr_exp_time; 37*433d6423SLionel Sambuc return old_head; 38*433d6423SLionel Sambuc } 39*433d6423SLionel Sambuc 40