timer.h 2.6 KB

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