/******************************************/ /* timer.h 0.2.0 (1999-Nov-13-Sat) */ /* Adam M. Costello */ /******************************************/ /* Get the current time, set timers that cause functions */ /* to be called in the future, and cancel timers. */ /* This is ANSI C code. */ #ifndef TIMER_H #define TIMER_H typedef struct { struct timer *timer; unsigned long serial; } timer_id; /* An identifier for a running timer, used to cancel the timer. */ /* Treat this as on opaque type (don't try to look inside). */ typedef void timer_handler(double now, void *who, void *what); /* A timer_handler is a function that gets called when a timer */ /* expires, and has the form expire(now,who,what), where now is */ /* the current time in seconds, and who and what are arbitrary */ /* pointers specified when the timer was set. See timer_set() */ /* below. */ double timer_now(void); /* Returns the current time in seconds. The origin */ /* (the time corresponding to 0) is unspecified. */ timer_id timer_set(timer_handler *expire, double when, void *who, void *what); /* Sets a timer. When the indicated time arrives the */ /* function expire(when,who,what) will be called. The */ /* who and what arguments can be anything, they are */ /* simply passed along. The returned timer_id can be */ /* passed to timer_cancel() to cancel the timer. If */ /* multiple timers are scheduled to expire at the same */ /* time, they will expire in the order they were set. */ /* If the requested expiration time is in the past, it */ /* is changed to the current time. */ int timer_cancel(timer_id timer); /* The timer must have been returned by timer_set(). If it is */ /* still running (has not yet expired or been canceled), it is */ /* canceled and 1 is returned, otherwise 0 is returned. */ #endif /* TIMER_H */