source: trunk/minix/include/timers.h@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 2.4 KB
Line 
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:
4 *
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
8 *
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.
13 */
14
15#ifndef _TIMERS_H
16#define _TIMERS_H
17
18#include <limits.h>
19#include <sys/types.h>
20
21struct timer;
22typedef void (*tmr_func_t)(struct timer *tp);
23typedef union { int ta_int; long ta_long; void *ta_ptr; } tmr_arg_t;
24
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.
28 */
29typedef struct timer
30{
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;
36
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)
41
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)
45
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.
49 */
50#define tmr_inittimer(tp) (void)((tp)->tmr_exp_time = TMR_NEVER, \
51 (tp)->tmr_next = NULL)
52
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.
56 */
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) );
61
62#endif /* _TIMERS_H */
63
Note: See TracBrowser for help on using the repository browser.