timer.h 2.4 KB

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