source: trunk/minix/lib/timers/tmrs_set.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.3 KB
Line 
1#include "timers.h"
2
3/*===========================================================================*
4 * tmrs_settimer *
5 *===========================================================================*/
6clock_t tmrs_settimer(tmrs, tp, exp_time, watchdog, new_head)
7timer_t **tmrs; /* pointer to timers queue */
8timer_t *tp; /* the timer to be added */
9clock_t exp_time; /* its expiration time */
10tmr_func_t watchdog; /* watchdog function to be run */
11clock_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 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
Note: See TracBrowser for help on using the repository browser.