xref: /minix/minix/lib/libtimers/tmrs_clr.c (revision 00e393ca)
1 #include <minix/timers.h>
2 
3 /*
4  * Deactivate a timer and remove it from the timers queue.  'tmrs' is a pointer
5  * to the timers queue.  'tp' is a pointer to the timer to be removed, which
6  * generally should be on the queue (but this is not a requirement, and the
7  * kernel abuses this).  If 'prev_time' is non-NULL, it is filled with the
8  * previous timer head time, which always exists since at least 'tp' is on it.
9  * The function returns TRUE if there is still at least one timer on the queue
10  * after this function is done, in which case 'next_time' (if non-NULL) is
11  * filled with the absolute expiry time of the new head timer.
12  */
13 int
14 tmrs_clrtimer(minix_timer_t ** tmrs, minix_timer_t * tp, clock_t * prev_time,
15 	clock_t * next_time)
16 {
17 	minix_timer_t **atp;
18 	int r;
19 
20 	if (*tmrs != NULL) {
21 		if (prev_time != NULL)
22 			*prev_time = (*tmrs)->tmr_exp_time;
23 		r = TRUE;
24 	} else
25 		r = FALSE;
26 
27 	tp->tmr_func = NULL;	/* clear the timer object */
28 
29 	for (atp = tmrs; *atp != NULL; atp = &(*atp)->tmr_next) {
30 		if (*atp == tp) {
31 			*atp = tp->tmr_next;
32 			break;
33 		}
34 	}
35 
36 	if (next_time != NULL) {
37 		if (*tmrs != NULL)
38 			*next_time = (*tmrs)->tmr_exp_time;
39 		else
40 			*next_time = 0;
41 	}
42 
43 	return r;
44 }
45