home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / TIMER.H < prev    next >
C/C++ Source or Header  |  1994-04-17  |  2KB  |  60 lines

  1. #ifndef _TIMER_H
  2. #define _TIMER_H
  3.   
  4. #ifndef _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.   
  8. /* Software timers
  9.  * There is one of these structures for each simulated timer.
  10.  * Whenever the timer is running, it is on a linked list
  11.  * pointed to by "Timers". The list is sorted in ascending order of
  12.  * expiration, with the first timer to expire at the head. This
  13.  * allows the timer process to avoid having to scan the entire list
  14.  * on every clock tick; once it finds an unexpired timer, it can
  15.  * stop searching.
  16.  *
  17.  * Stopping a timer or letting it expire causes it to be removed
  18.  * from the list. Starting a timer puts it on the list at the right
  19.  * place.
  20.  */
  21. struct timer {
  22.     struct timer *next; /* Linked-list pointer */
  23.     int32 duration;     /* Duration of timer, in ticks */
  24.     int32 expiration;   /* Clock time at expiration */
  25.     void (*func) __ARGS((void *));  /* Function to call at expiration */
  26.     void *arg;      /* Arg to pass function */
  27.     char state;     /* Timer state */
  28. #define TIMER_STOP  0
  29. #define TIMER_RUN   1
  30. #define TIMER_EXPIRE    2
  31. };
  32. #define NULLTIMER   (struct timer *)0
  33. #define MAX_TIME    (int32)4294967295   /* Max long integer */
  34. #ifndef MSPTICK
  35. #define MSPTICK     55      /* Milliseconds per tick */
  36. #endif
  37. /* Useful user macros that hide the timer structure internals */
  38. #define dur_timer(t)    ((t)->duration*MSPTICK)
  39. #define run_timer(t)    ((t)->state == TIMER_RUN)
  40.   
  41. extern volatile int Tick;
  42. #ifndef LINUX
  43. extern void (*Cfunc[])();   /* List of clock tick functions */
  44. #endif
  45.   
  46. /* In timer.c: */
  47. void alarm __ARGS((int32 ms));
  48. int pause __ARGS((int32 ms));
  49. int32 read_timer __ARGS((struct timer *t));
  50. void set_timer __ARGS((struct timer *t,int32 x));
  51. void start_timer __ARGS((struct timer *t));
  52. void stop_timer __ARGS((struct timer *timer));
  53. char *tformat __ARGS((int32 t));
  54.   
  55. /* In hardware.c: */
  56. int32 msclock __ARGS((void));
  57. int32 secclock __ARGS((void));
  58.   
  59. #endif  /* _TIMER_H */
  60.