minix/lib/libsys/timers.c
Thomas Veerman a209c3ae12 Fix a ton of compiler warnings
This patch fixes most of current reasons to generate compiler warnings.
The changes consist of:
 - adding missing casts
 - hiding or unhiding function declarations
 - including headers where missing
 - add __UNCONST when assigning a const char * to a char *
 - adding missing return statements
 - changing some types from unsigned to signed, as the code seems to want
   signed ints
 - converting old-style function definitions to current style (i.e.,
   void func(param1, param2) short param1, param2; {...} to
   void func (short param1, short param2) {...})
 - making the compiler silent about signed vs unsigned comparisons. We
   have too many of those in the new libc to fix.

A number of bugs in the test set were fixed. These bugs were never
triggered with our old libc. Consequently, these tests are now forced to
link with the new libc or they will generate errors (in particular tests 43
and 55).

Most changes in NetBSD libc are limited to moving aroudn "#ifndef __minix"
or stuff related to Minix-specific things (code in sys-minix or gen/minix).
2011-11-14 10:07:49 +00:00

89 lines
3.5 KiB
C

/* Watchdog timer management. These functions in this file provide a
* convenient interface to the timers library that manages a list of
* watchdog timers. All details of scheduling an alarm at the CLOCK task
* are hidden behind this interface.
*
* The entry points into this file are:
* init_timer: initialize a timer structure
* set_timer: reset and existing or set a new watchdog timer
* cancel_timer: remove a timer from the list of timers
* expire_timers: check for expired timers and run watchdog functions
*
*/
#include "syslib.h"
#include <timers.h>
#include <minix/sysutil.h>
PRIVATE timer_t *timers = NULL;
PRIVATE int expiring = 0;
/*===========================================================================*
* init_timer *
*===========================================================================*/
PUBLIC void init_timer(timer_t *tp)
{
tmr_inittimer(tp);
}
/*===========================================================================*
* set_timer *
*===========================================================================*/
PUBLIC void set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
{
int r;
clock_t now, prev_time = 0, next_time;
if ((r = getuptime(&now)) != OK)
panic("set_timer: couldn't get uptime");
/* Set timer argument and add timer to the list. */
tmr_arg(tp)->ta_int = arg;
prev_time = tmrs_settimer(&timers, tp, now+ticks, watchdog, &next_time);
/* Reschedule our synchronous alarm if necessary. */
if (expiring == 0 && (! prev_time || prev_time > next_time)) {
if (sys_setalarm(next_time, 1) != OK)
panic("set_timer: couldn't set alarm");
}
}
/*===========================================================================*
* cancel_timer *
*===========================================================================*/
PUBLIC void cancel_timer(timer_t *tp)
{
clock_t next_time, prev_time;
prev_time = tmrs_clrtimer(&timers, tp, &next_time);
/* If the earliest timer has been removed, we have to set the alarm to
* the next timer, or cancel the alarm altogether if the last timer
* has been cancelled (next_time will be 0 then).
*/
if (expiring == 0 && (prev_time < next_time || ! next_time)) {
if (sys_setalarm(next_time, 1) != OK)
panic("cancel_timer: couldn't set alarm");
}
}
/*===========================================================================*
* expire_timers *
*===========================================================================*/
PUBLIC void expire_timers(clock_t now)
{
clock_t next_time;
/* Check for expired timers. Use a global variable to indicate that
* watchdog functions are called, so that sys_setalarm() isn't called
* more often than necessary when set_timer or cancel_timer are called
* from these watchdog functions. */
expiring = 1;
tmrs_exptimers(&timers, now, &next_time);
expiring = 0;
/* Reschedule an alarm if necessary. */
if (next_time > 0) {
if (sys_setalarm(next_time, 1) != OK)
panic("expire_timers: couldn't set alarm");
}
}