2005-06-17 15:49:56 +02:00
|
|
|
/* FS timers library
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
#include <timers.h>
|
|
|
|
#include <minix/syslib.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
|
|
|
|
PRIVATE timer_t *fs_timers = NULL;
|
|
|
|
|
|
|
|
PUBLIC void fs_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
clock_t now, old_head = 0, new_head;
|
|
|
|
|
2005-09-11 18:45:46 +02:00
|
|
|
if ((r = getuptime(&now)) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("FS couldn't get uptime from system task");
|
2005-06-17 15:49:56 +02:00
|
|
|
|
|
|
|
tmr_arg(tp)->ta_int = arg;
|
|
|
|
|
|
|
|
old_head = tmrs_settimer(&fs_timers, tp, now+ticks, watchdog, &new_head);
|
|
|
|
|
|
|
|
/* reschedule our synchronous alarm if necessary */
|
2005-09-11 18:45:46 +02:00
|
|
|
if (!old_head || old_head > new_head) {
|
|
|
|
if (sys_setalarm(new_head, 1) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("FS set timer couldn't set synchronous alarm");
|
2005-06-17 15:49:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUBLIC void fs_expire_timers(clock_t now)
|
|
|
|
{
|
|
|
|
clock_t new_head;
|
|
|
|
tmrs_exptimers(&fs_timers, now, &new_head);
|
2005-09-11 18:45:46 +02:00
|
|
|
if (new_head > 0) {
|
|
|
|
if (sys_setalarm(new_head, 1) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("FS expire timer couldn't set synchronous alarm");
|
2005-06-17 15:49:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-22 20:28:32 +02:00
|
|
|
PUBLIC void fs_init_timer(timer_t *tp)
|
|
|
|
{
|
|
|
|
tmr_inittimer(tp);
|
|
|
|
}
|
|
|
|
|
2005-06-17 15:49:56 +02:00
|
|
|
PUBLIC void fs_cancel_timer(timer_t *tp)
|
|
|
|
{
|
|
|
|
clock_t new_head, old_head;
|
|
|
|
old_head = tmrs_clrtimer(&fs_timers, tp, &new_head);
|
|
|
|
|
|
|
|
/* if the earliest timer has been removed, we have to set
|
|
|
|
* the synalarm to the next timer, or cancel the synalarm
|
|
|
|
* altogether if th last time has been cancelled (new_head
|
|
|
|
* will be 0 then).
|
|
|
|
*/
|
2005-09-11 18:45:46 +02:00
|
|
|
if (old_head < new_head || !new_head) {
|
|
|
|
if (sys_setalarm(new_head, 1) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("FS expire timer couldn't set synchronous alarm");
|
2005-06-17 15:49:56 +02:00
|
|
|
}
|
|
|
|
}
|