timer.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /*
  52. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  53. * locks the timer base:
  54. */
  55. extern unsigned long next_timer_interrupt(void);
  56. /*
  57. * Return when the next timer-wheel timeout occurs (in absolute jiffies),
  58. * locks the timer base and does the comparison against the given
  59. * jiffie.
  60. */
  61. extern unsigned long get_next_timer_interrupt(unsigned long now);
  62. /**
  63. * add_timer - start a timer
  64. * @timer: the timer to be added
  65. *
  66. * The kernel will do a ->function(->data) callback from the
  67. * timer interrupt at the ->expires point in the future. The
  68. * current time is 'jiffies'.
  69. *
  70. * The timer's ->expires, ->function (and if the handler uses it, ->data)
  71. * fields must be set prior calling this function.
  72. *
  73. * Timers with an ->expires field in the past will be executed in the next
  74. * timer tick.
  75. */
  76. static inline void add_timer(struct timer_list *timer)
  77. {
  78. BUG_ON(timer_pending(timer));
  79. __mod_timer(timer, timer->expires);
  80. }
  81. #ifdef CONFIG_SMP
  82. extern int try_to_del_timer_sync(struct timer_list *timer);
  83. extern int del_timer_sync(struct timer_list *timer);
  84. #else
  85. # define try_to_del_timer_sync(t) del_timer(t)
  86. # define del_timer_sync(t) del_timer(t)
  87. #endif
  88. #define del_singleshot_timer_sync(t) del_timer_sync(t)
  89. extern void init_timers(void);
  90. extern void run_local_timers(void);
  91. struct hrtimer;
  92. extern enum hrtimer_restart it_real_fn(struct hrtimer *);
  93. unsigned long __round_jiffies(unsigned long j, int cpu);
  94. unsigned long __round_jiffies_relative(unsigned long j, int cpu);
  95. unsigned long round_jiffies(unsigned long j);
  96. unsigned long round_jiffies_relative(unsigned long j);
  97. #endif