timer.h 2.6 KB

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