blob: c982304dbafd4f30faf9764c377b442894f20282 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_TIMER_H
2#define _LINUX_TIMER_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/list.h>
5#include <linux/spinlock.h>
6#include <linux/stddef.h>
7
Oleg Nesterov3691c512006-03-31 02:30:30 -08008struct tvec_t_base_s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10struct timer_list {
11 struct list_head entry;
12 unsigned long expires;
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 void (*function)(unsigned long);
15 unsigned long data;
16
Oleg Nesterov3691c512006-03-31 02:30:30 -080017 struct tvec_t_base_s *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018};
19
Oleg Nesterov3691c512006-03-31 02:30:30 -080020extern struct tvec_t_base_s boot_tvec_bases;
Oleg Nesterov55c888d2005-06-23 00:08:56 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#define TIMER_INITIALIZER(_function, _expires, _data) { \
23 .function = (_function), \
24 .expires = (_expires), \
25 .data = (_data), \
Oleg Nesterov3691c512006-03-31 02:30:30 -080026 .base = &boot_tvec_bases, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 }
28
Ingo Molnar8d06afa2005-09-09 13:10:40 -070029#define DEFINE_TIMER(_name, _function, _expires, _data) \
30 struct timer_list _name = \
31 TIMER_INITIALIZER(_function, _expires, _data)
32
Oleg Nesterov55c888d2005-06-23 00:08:56 -070033void fastcall init_timer(struct timer_list * timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Oleg Nesterova8db2db2005-10-30 15:01:38 -080035static inline void setup_timer(struct timer_list * timer,
36 void (*function)(unsigned long),
37 unsigned long data)
38{
39 timer->function = function;
40 timer->data = data;
41 init_timer(timer);
42}
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/***
45 * timer_pending - is a timer pending?
46 * @timer: the timer in question
47 *
48 * timer_pending will tell whether a given timer is currently pending,
49 * or not. Callers must ensure serialization wrt. other operations done
50 * to this timer, eg. interrupt contexts, or other CPUs on SMP.
51 *
52 * return value: 1 if the timer is pending, 0 if not.
53 */
54static inline int timer_pending(const struct timer_list * timer)
55{
Oleg Nesterov55c888d2005-06-23 00:08:56 -070056 return timer->entry.next != NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
59extern void add_timer_on(struct timer_list *timer, int cpu);
60extern int del_timer(struct timer_list * timer);
61extern int __mod_timer(struct timer_list *timer, unsigned long expires);
62extern int mod_timer(struct timer_list *timer, unsigned long expires);
63
64extern unsigned long next_timer_interrupt(void);
65
66/***
67 * add_timer - start a timer
68 * @timer: the timer to be added
69 *
70 * The kernel will do a ->function(->data) callback from the
Andrzej Zaborowski13fce802006-03-24 18:13:37 +010071 * timer interrupt at the ->expires point in the future. The
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * current time is 'jiffies'.
73 *
Andrzej Zaborowski13fce802006-03-24 18:13:37 +010074 * The timer's ->expires, ->function (and if the handler uses it, ->data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 * fields must be set prior calling this function.
76 *
Andrzej Zaborowski13fce802006-03-24 18:13:37 +010077 * Timers with an ->expires field in the past will be executed in the next
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 * timer tick.
79 */
Andrew Morton15d2bac2005-10-30 15:02:24 -080080static inline void add_timer(struct timer_list *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Andrew Morton15d2bac2005-10-30 15:02:24 -080082 BUG_ON(timer_pending(timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 __mod_timer(timer, timer->expires);
84}
85
86#ifdef CONFIG_SMP
Oleg Nesterovfd450b72005-06-23 00:08:59 -070087 extern int try_to_del_timer_sync(struct timer_list *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 extern int del_timer_sync(struct timer_list *timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#else
Oleg Nesterovfd450b72005-06-23 00:08:59 -070090# define try_to_del_timer_sync(t) del_timer(t)
91# define del_timer_sync(t) del_timer(t)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#endif
93
Oleg Nesterov55c888d2005-06-23 00:08:56 -070094#define del_singleshot_timer_sync(t) del_timer_sync(t)
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern void init_timers(void);
97extern void run_local_timers(void);
Roman Zippel05cfb612006-03-26 01:38:12 -080098struct hrtimer;
99extern int it_real_fn(struct hrtimer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101#endif