home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / Include / Linux / timer.h < prev    next >
C/C++ Source or Header  |  2002-04-26  |  3KB  |  90 lines

  1. /* $Id: timer.h,v 1.2 2002/04/26 23:09:16 smilcke Exp $ */
  2.  
  3. #ifndef _LINUX_TIMER_H
  4. #define _LINUX_TIMER_H
  5.  
  6. #ifndef TARGET_OS2
  7. #include <linux/config.h>
  8. #endif
  9. #include <linux/list.h>
  10.  
  11. /*
  12.  * In Linux 2.4, static timers have been removed from the kernel.
  13.  * Timers may be dynamically created and destroyed, and should be initialized
  14.  * by a call to init_timer() upon creation.
  15.  *
  16.  * The "data" field enables use of a common timeout function for several
  17.  * timeouts. You can use this field to distinguish between the different
  18.  * invocations.
  19.  */
  20. struct timer_list {
  21.     struct list_head list;
  22.     unsigned long expires;
  23.     unsigned long data;
  24.     void (*function)(unsigned long);
  25. };
  26.  
  27. #if (defined(TARGET_OS2) && !defined(NOOS2LXAPI))
  28. extern void (*add_timer)(struct timer_list * timer);
  29. extern int (*del_timer)(struct timer_list * timer);
  30. #else
  31. extern void add_timer(struct timer_list * timer);
  32. extern int del_timer(struct timer_list * timer);
  33. #endif
  34.  
  35. #ifdef CONFIG_SMP
  36. extern int del_timer_sync(struct timer_list * timer);
  37. extern void sync_timers(void);
  38. #else
  39. #define del_timer_sync(t)    del_timer(t)
  40. #define sync_timers()        do { } while (0)
  41. #endif
  42.  
  43. /*
  44.  * mod_timer is a more efficient way to update the expire field of an
  45.  * active timer (if the timer is inactive it will be activated)
  46.  * mod_timer(a,b) is equivalent to del_timer(a); a->expires = b; add_timer(a).
  47.  * If the timer is known to be not pending (ie, in the handler), mod_timer
  48.  * is less efficient than a->expires = b; add_timer(a).
  49.  */
  50. #if (defined(TARGET_OS2) && !defined(NOOS2LXAPI))
  51. extern int (*mod_timer)(struct timer_list *timer, unsigned long expires);
  52. #else
  53. int mod_timer(struct timer_list *timer, unsigned long expires);
  54. #endif
  55.  
  56. extern void it_real_fn(unsigned long);
  57.  
  58. #ifndef TARGET_OS2
  59. static inline void init_timer(struct timer_list * timer)
  60. {
  61.     timer->list.next = timer->list.prev = NULL;
  62. }
  63. #endif
  64.  
  65. #ifndef TARGET_OS2
  66. static inline int timer_pending (const struct timer_list * timer)
  67. {
  68.     return timer->list.next != NULL;
  69. }
  70. #endif
  71.  
  72. /*
  73.  *    These inlines deal with timer wrapping correctly. You are
  74.  *    strongly encouraged to use them
  75.  *    1. Because people otherwise forget
  76.  *    2. Because if the timer wrap changes in future you wont have to
  77.  *       alter your driver code.
  78.  *
  79.  * Do this with "<0" and ">=0" to only test the sign of the result. A
  80.  * good compiler would generate better code (and a really good compiler
  81.  * wouldn't care). Gcc is currently neither.
  82.  */
  83. #define time_after(a,b)        ((long)(b) - (long)(a) < 0)
  84. #define time_before(a,b)    time_after(b,a)
  85.  
  86. #define time_after_eq(a,b)    ((long)(a) - (long)(b) >= 0)
  87. #define time_before_eq(a,b)    time_after_eq(b,a)
  88.  
  89. #endif
  90.