timer.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /***
  30. * timer_pending - is a timer pending?
  31. * @timer: the timer in question
  32. *
  33. * timer_pending will tell whether a given timer is currently pending,
  34. * or not. Callers must ensure serialization wrt. other operations done
  35. * to this timer, eg. interrupt contexts, or other CPUs on SMP.
  36. *
  37. * return value: 1 if the timer is pending, 0 if not.
  38. */
  39. static inline int timer_pending(const struct timer_list * timer)
  40. {
  41. return timer->entry.next != NULL;
  42. }
  43. extern void add_timer_on(struct timer_list *timer, int cpu);
  44. extern int del_timer(struct timer_list * timer);
  45. extern int __mod_timer(struct timer_list *timer, unsigned long expires);
  46. extern int mod_timer(struct timer_list *timer, unsigned long expires);
  47. extern unsigned long next_timer_interrupt(void);
  48. /***
  49. * add_timer - start a timer
  50. * @timer: the timer to be added
  51. *
  52. * The kernel will do a ->function(->data) callback from the
  53. * timer interrupt at the ->expired point in the future. The
  54. * current time is 'jiffies'.
  55. *
  56. * The timer's ->expired, ->function (and if the handler uses it, ->data)
  57. * fields must be set prior calling this function.
  58. *
  59. * Timers with an ->expired field in the past will be executed in the next
  60. * timer tick.
  61. */
  62. static inline void add_timer(struct timer_list * timer)
  63. {
  64. __mod_timer(timer, timer->expires);
  65. }
  66. #ifdef CONFIG_SMP
  67. extern int try_to_del_timer_sync(struct timer_list *timer);
  68. extern int del_timer_sync(struct timer_list *timer);
  69. #else
  70. # define try_to_del_timer_sync(t) del_timer(t)
  71. # define del_timer_sync(t) del_timer(t)
  72. #endif
  73. #define del_singleshot_timer_sync(t) del_timer_sync(t)
  74. extern void init_timers(void);
  75. extern void run_local_timers(void);
  76. extern void it_real_fn(unsigned long);
  77. #endif