Merge of VFS by Balasz Gerofi with Minix trunk.
[minix3.git] / servers / vfs / timers.c
blob7c10ac32ecf94e624238f4117b33c59bbf63cfe2
1 /* FS timers library
2 */
4 #include "fs.h"
6 #include <timers.h>
7 #include <minix/syslib.h>
8 #include <minix/com.h>
10 PRIVATE timer_t *fs_timers = NULL;
12 PUBLIC void fs_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
14 int r;
15 clock_t now, old_head = 0, new_head;
17 if ((r = getuptime(&now)) != OK)
18 panic(__FILE__, "FS couldn't get uptime from system task.", NO_NUM);
20 tmr_arg(tp)->ta_int = arg;
22 old_head = tmrs_settimer(&fs_timers, tp, now+ticks, watchdog, &new_head);
24 /* reschedule our synchronous alarm if necessary */
25 if (!old_head || old_head > new_head) {
26 if (sys_setalarm(new_head, 1) != OK)
27 panic(__FILE__, "FS set timer "
28 "couldn't set synchronous alarm.", NO_NUM);
31 return;
34 PUBLIC void fs_expire_timers(clock_t now)
36 clock_t new_head;
37 tmrs_exptimers(&fs_timers, now, &new_head);
38 if (new_head > 0) {
39 if (sys_setalarm(new_head, 1) != OK)
40 panic(__FILE__, "FS expire timer couldn't set "
41 "synchronous alarm.", NO_NUM);
45 PUBLIC void fs_init_timer(timer_t *tp)
47 tmr_inittimer(tp);
50 PUBLIC void fs_cancel_timer(timer_t *tp)
52 clock_t new_head, old_head;
53 old_head = tmrs_clrtimer(&fs_timers, tp, &new_head);
55 /* if the earliest timer has been removed, we have to set
56 * the synalarm to the next timer, or cancel the synalarm
57 * altogether if th last time has been cancelled (new_head
58 * will be 0 then).
60 if (old_head < new_head || !new_head) {
61 if (sys_setalarm(new_head, 1) != OK)
62 panic(__FILE__,
63 "FS expire timer couldn't set synchronous alarm.",
64 NO_NUM);