kernel: print spurious interrupt message with increasing interval.
[minix.git] / include / timers.h
blobe88d5674a25c7e7b11cb3b1903c1194f95a3a6b8
1 /* This library provides generic watchdog timer management functionality.
2 * The functions operate on a timer queue provided by the caller. Note that
3 * the timers must use absolute time to allow sorting. The library provides:
5 * tmrs_settimer: (re)set a new watchdog timer in the timers queue
6 * tmrs_clrtimer: remove a timer from both the timers queue
7 * tmrs_exptimers: check for expired timers and run watchdog functions
9 * Author:
10 * Jorrit N. Herder <jnherder@cs.vu.nl>
11 * Adapted from tmr_settimer and tmr_clrtimer in src/kernel/clock.c.
12 * Last modified: September 30, 2004.
15 #ifndef _TIMERS_H
16 #define _TIMERS_H
18 #include <limits.h>
19 #include <minix/types.h>
21 struct timer;
22 typedef void (*tmr_func_t)(struct timer *tp);
23 typedef union { int ta_int; long ta_long; void *ta_ptr; } tmr_arg_t;
25 /* A timer_t variable must be declare for each distinct timer to be used.
26 * The timers watchdog function and expiration time are automatically set
27 * by the library function tmrs_settimer, but its argument is not.
29 typedef struct timer
31 struct timer *tmr_next; /* next in a timer chain */
32 clock_t tmr_exp_time; /* expiration time */
33 tmr_func_t tmr_func; /* function to call when expired */
34 tmr_arg_t tmr_arg; /* random argument */
35 } timer_t;
37 /* Used when the timer is not active. */
38 #define TMR_NEVER ((clock_t) -1 < 0) ? ((clock_t) LONG_MAX) : ((clock_t) -1)
39 #undef TMR_NEVER
40 #define TMR_NEVER ((clock_t) LONG_MAX)
42 /* These definitions can be used to set or get data from a timer variable. */
43 #define tmr_arg(tp) (&(tp)->tmr_arg)
44 #define tmr_exp_time(tp) (&(tp)->tmr_exp_time)
46 /* Timers should be initialized once before they are being used. Be careful
47 * not to reinitialize a timer that is in a list of timers, or the chain
48 * will be broken.
50 #define tmr_inittimer(tp) (void)((tp)->tmr_exp_time = TMR_NEVER, \
51 (tp)->tmr_next = NULL)
53 /* The following generic timer management functions are available. They
54 * can be used to operate on the lists of timers. Adding a timer to a list
55 * automatically takes care of removing it.
57 _PROTOTYPE( clock_t tmrs_clrtimer, (timer_t **tmrs, timer_t *tp, clock_t *new_head) );
58 _PROTOTYPE( void tmrs_exptimers, (timer_t **tmrs, clock_t now, clock_t *new_head) );
59 _PROTOTYPE( clock_t tmrs_settimer, (timer_t **tmrs, timer_t *tp,
60 clock_t exp_time, tmr_func_t watchdog, clock_t *new_head) );
62 #endif /* _TIMERS_H */