timer.h 2.7 KB

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