ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / linux / timer.h
1 #ifndef _LINUX_TIMER_H
2 #define _LINUX_TIMER_H
3
4 #include <linux/config.h>
5 #include <linux/list.h>
6 #include <linux/spinlock.h>
7
8 struct tvec_t_base_s;
9
10 struct timer_list {
11         struct list_head entry;
12         unsigned long expires;
13
14         spinlock_t lock;
15         unsigned long magic;
16
17         void (*function)(unsigned long);
18         unsigned long data;
19
20         struct tvec_t_base_s *base;
21 };
22
23 #define TIMER_MAGIC     0x4b87ad6e
24
25 #define TIMER_INITIALIZER(_function, _expires, _data) {         \
26                 .function = (_function),                        \
27                 .expires = (_expires),                          \
28                 .data = (_data),                                \
29                 .base = NULL,                                   \
30                 .magic = TIMER_MAGIC,                           \
31                 .lock = SPIN_LOCK_UNLOCKED,                     \
32         }
33
34 /***
35  * init_timer - initialize a timer.
36  * @timer: the timer to be initialized
37  *
38  * init_timer() must be done to a timer prior calling *any* of the
39  * other timer functions.
40  */
41 static inline void init_timer(struct timer_list * timer)
42 {
43         timer->base = NULL;
44         timer->magic = TIMER_MAGIC;
45         spin_lock_init(&timer->lock);
46 }
47
48 /***
49  * timer_pending - is a timer pending?
50  * @timer: the timer in question
51  *
52  * timer_pending will tell whether a given timer is currently pending,
53  * or not. Callers must ensure serialization wrt. other operations done
54  * to this timer, eg. interrupt contexts, or other CPUs on SMP.
55  *
56  * return value: 1 if the timer is pending, 0 if not.
57  */
58 static inline int timer_pending(const struct timer_list * timer)
59 {
60         return timer->base != NULL;
61 }
62
63 extern void add_timer_on(struct timer_list *timer, int cpu);
64 extern int del_timer(struct timer_list * timer);
65 extern int __mod_timer(struct timer_list *timer, unsigned long expires);
66 extern int mod_timer(struct timer_list *timer, unsigned long expires);
67
68 extern unsigned long next_timer_interrupt(void);
69
70 /***
71  * add_timer - start a timer
72  * @timer: the timer to be added
73  *
74  * The kernel will do a ->function(->data) callback from the
75  * timer interrupt at the ->expired point in the future. The
76  * current time is 'jiffies'.
77  *
78  * The timer's ->expired, ->function (and if the handler uses it, ->data)
79  * fields must be set prior calling this function.
80  *
81  * Timers with an ->expired field in the past will be executed in the next
82  * timer tick.
83  */
84 static inline void add_timer(struct timer_list * timer)
85 {
86         __mod_timer(timer, timer->expires);
87 }
88
89 #ifdef CONFIG_SMP
90   extern int del_timer_sync(struct timer_list * timer);
91 #else
92 # define del_timer_sync(t) del_timer(t)
93 #endif
94
95 extern void init_timers(void);
96 extern void run_local_timers(void);
97 extern void it_real_fn(unsigned long);
98
99 #endif