source: branches/minix3-book/servers/fs/timers.c@ 23

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

Importazione sorgenti libro

File size: 1.5 KB
Line 
1/* FS timers library
2 */
3
4#include "fs.h"
5
6#include <timers.h>
7#include <minix/syslib.h>
8#include <minix/com.h>
9
10PRIVATE timer_t *fs_timers = NULL;
11
12PUBLIC void fs_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
13{
14 int r;
15 clock_t now, old_head = 0, new_head;
16
17 if ((r = getuptime(&now)) != OK)
18 panic(__FILE__, "FS couldn't get uptime from system task.", NO_NUM);
19
20 tmr_arg(tp)->ta_int = arg;
21
22 old_head = tmrs_settimer(&fs_timers, tp, now+ticks, watchdog, &new_head);
23
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);
29 }
30
31 return;
32}
33
34PUBLIC void fs_expire_timers(clock_t now)
35{
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);
42 }
43}
44
45PUBLIC void fs_init_timer(timer_t *tp)
46{
47 tmr_inittimer(tp);
48}
49
50PUBLIC void fs_cancel_timer(timer_t *tp)
51{
52 clock_t new_head, old_head;
53 old_head = tmrs_clrtimer(&fs_timers, tp, &new_head);
54
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).
59 */
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);
65 }
66}
Note: See TracBrowser for help on using the repository browser.