timer.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _LINUX_TIMER_H
  2. #define _LINUX_TIMER_H
  3. #include <linux/config.h>
  4. #include <linux/list.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/stddef.h>
  7. struct tvec_t_base_s;
  8. struct timer_list {
  9. struct list_head entry;
  10. unsigned long expires;
  11. spinlock_t lock;
  12. unsigned long magic;
  13. void (*function)(unsigned long);
  14. unsigned long data;
  15. struct tvec_t_base_s *base;
  16. };
  17. #define TIMER_MAGIC 0x4b87ad6e
  18. #define TIMER_INITIALIZER(_function, _expires, _data) { \
  19. .function = (_function), \
  20. .expires = (_expires), \
  21. .data = (_data), \
  22. .base = NULL, \
  23. .magic = TIMER_MAGIC, \
  24. .lock = SPIN_LOCK_UNLOCKED, \
  25. }
  26. /***
  27. * init_timer - initialize a timer.
  28. * @timer: the timer to be initialized
  29. *
  30. * init_timer() must be done to a timer prior calling *any* of the
  31. * other timer functions.
  32. */
  33. static inline void init_timer(struct timer_list * timer)
  34. {
  35. timer->base = NULL;
  36. timer->magic = TIMER_MAGIC;
  37. spin_lock_init(&timer->lock);
  38. }
  39. /***
  40. * timer_pending - is a timer pending?
  41. * @timer: the timer in question
  42. *
  43. * timer_pending will tell whether a given timer is currently pending,
  44. * or not. Callers must ensure serialization wrt. other operations done
  45. * to this timer, eg. interrupt contexts, or other CPUs on SMP.
  46. *
  47. * return value: 1 if the timer is pending, 0 if not.
  48. */
  49. static inline int timer_pending(const struct timer_list * timer)
  50. {
  51. return timer->base != NULL;
  52. }
  53. extern void add_timer_on(struct timer_list *timer, int cpu);
  54. extern int del_timer(struct timer_list * timer);
  55. extern int __mod_timer(struct timer_list *timer, unsigned long expires);
  56. extern int mod_timer(struct timer_list *timer, unsigned long expires);
  57. extern unsigned long next_timer_interrupt(void);
  58. /***
  59. * add_timer - start a timer
  60. * @timer: the timer to be added
  61. *
  62. * The kernel will do a ->function(->data) callback from the
  63. * timer interrupt at the ->expired point in the future. The
  64. * current time is 'jiffies'.
  65. *
  66. * The timer's ->expired, ->function (and if the handler uses it, ->data)
  67. * fields must be set prior calling this function.
  68. *
  69. * Timers with an ->expired field in the past will be executed in the next
  70. * timer tick.
  71. */
  72. static inline void add_timer(struct timer_list * timer)
  73. {
  74. __mod_timer(timer, timer->expires);
  75. }
  76. #ifdef CONFIG_SMP
  77. extern int del_timer_sync(struct timer_list *timer);
  78. extern int del_singleshot_timer_sync(struct timer_list *timer);
  79. #else
  80. # define del_timer_sync(t) del_timer(t)
  81. # define del_singleshot_timer_sync(t) del_timer(t)
  82. #endif
  83. extern void init_timers(void);
  84. extern void run_local_timers(void);
  85. extern void it_real_fn(unsigned long);
  86. #endif