1 #ifndef _LINUX_TIMER_H
2 #define _LINUX_TIMER_H
3 
4 #include <linux/config.h>
5 #include <linux/list.h>
6 
7 /*
8  * In Linux 2.4, static timers have been removed from the kernel.
9  * Timers may be dynamically created and destroyed, and should be initialized
10  * by a call to init_timer() upon creation.
11  *
12  * The "data" field enables use of a common timeout function for several
13  * timeouts. You can use this field to distinguish between the different
14  * invocations.
15  */
16 struct timer_list {
17 	struct list_head list;
18 	unsigned long expires;
19 	unsigned long data;
20 	void (*function)(unsigned long);
21 };
22 
23 extern void add_timer(struct timer_list * timer);
24 extern int del_timer(struct timer_list * timer);
25 
26 #ifdef CONFIG_SMP
27 extern int del_timer_sync(struct timer_list * timer);
28 extern void sync_timers(void);
29 #else
30 #define del_timer_sync(t)	del_timer(t)
31 #define sync_timers()		do { } while (0)
32 #endif
33 
34 /*
35  * mod_timer is a more efficient way to update the expire field of an
36  * active timer (if the timer is inactive it will be activated)
37  * mod_timer(a,b) is equivalent to del_timer(a); a->expires = b; add_timer(a).
38  * If the timer is known to be not pending (ie, in the handler), mod_timer
39  * is less efficient than a->expires = b; add_timer(a).
40  */
41 int mod_timer(struct timer_list *timer, unsigned long expires);
42 
43 extern void it_real_fn(unsigned long);
44 
init_timer(struct timer_list * timer)45 static inline void init_timer(struct timer_list * timer)
46 {
47 	timer->list.next = timer->list.prev = NULL;
48 }
49 
timer_pending(const struct timer_list * timer)50 static inline int timer_pending (const struct timer_list * timer)
51 {
52 	return timer->list.next != NULL;
53 }
54 
55 /*
56  *	These inlines deal with timer wrapping correctly. You are
57  *	strongly encouraged to use them
58  *	1. Because people otherwise forget
59  *	2. Because if the timer wrap changes in future you wont have to
60  *	   alter your driver code.
61  *
62  * time_after(a,b) returns true if the time a is after time b.
63  *
64  * Do this with "<0" and ">=0" to only test the sign of the result. A
65  * good compiler would generate better code (and a really good compiler
66  * wouldn't care). Gcc is currently neither.
67  */
68 #define time_after(a,b)		((long)(b) - (long)(a) < 0)
69 #define time_before(a,b)	time_after(b,a)
70 
71 #define time_after_eq(a,b)	((long)(a) - (long)(b) >= 0)
72 #define time_before_eq(a,b)	time_after_eq(b,a)
73 
74 #endif
75