aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-08-08 14:10:27 -0400
committerThomas Gleixner <tglx@linutronix.de>2012-08-21 10:28:30 -0400
commitfc683995a6c4e604d62ab9a488ac2c1ba94fa868 (patch)
treec43956da7c1fc34446d40d64f7cff81475915fee /include
parent5a9af38d05f6a1bd0d3f1f69a074cdbe9c87e977 (diff)
timer: Clean up timer initializers
Over time, timer initializers became messy with unnecessarily duplicated code which are inconsistently spread across timer.h and timer.c. This patch cleans up timer initializers. * timer.c::__init_timer() is renamed to do_init_timer(). * __TIMER_INITIALIZER() added. It takes @flags and all initializers are wrappers around it. * init_timer[_on_stack]_key() now take @flags. * __init_timer[_on_stack]() added. They take @flags and all init macros are wrappers around them. * __setup_timer[_on_stack]() added. It uses __init_timer() and takes @flags. All setup macros are wrappers around the two. Note that this patch doesn't add missing init/setup combinations - e.g. init_timer_deferrable_on_stack(). Adding missing ones is trivial. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: torvalds@linux-foundation.org Cc: peterz@infradead.org Link: http://lkml.kernel.org/r/1344449428-24962-4-git-send-email-tj@kernel.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/linux/timer.h123
1 files changed, 39 insertions, 84 deletions
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 1d364aed1802..3f95c1fa615e 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -62,136 +62,91 @@ extern struct tvec_base boot_tvec_bases;
62 62
63#define TIMER_FLAG_MASK 0x1LU 63#define TIMER_FLAG_MASK 0x1LU
64 64
65#define TIMER_INITIALIZER(_function, _expires, _data) { \ 65#define __TIMER_INITIALIZER(_function, _expires, _data, _flags) { \
66 .entry = { .prev = TIMER_ENTRY_STATIC }, \ 66 .entry = { .prev = TIMER_ENTRY_STATIC }, \
67 .function = (_function), \ 67 .function = (_function), \
68 .expires = (_expires), \ 68 .expires = (_expires), \
69 .data = (_data), \ 69 .data = (_data), \
70 .base = &boot_tvec_bases, \ 70 .base = (void *)((unsigned long)&boot_tvec_bases + (_flags)), \
71 .slack = -1, \ 71 .slack = -1, \
72 __TIMER_LOCKDEP_MAP_INITIALIZER( \ 72 __TIMER_LOCKDEP_MAP_INITIALIZER( \
73 __FILE__ ":" __stringify(__LINE__)) \ 73 __FILE__ ":" __stringify(__LINE__)) \
74 } 74 }
75 75
76#define TBASE_MAKE_DEFERRED(ptr) ((struct tvec_base *) \ 76#define TIMER_INITIALIZER(_function, _expires, _data) \
77 ((unsigned char *)(ptr) + TIMER_DEFERRABLE)) 77 __TIMER_INITIALIZER((_function), (_expires), (_data), 0)
78 78
79#define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) {\ 79#define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) \
80 .entry = { .prev = TIMER_ENTRY_STATIC }, \ 80 __TIMER_INITIALIZER((_function), (_expires), (_data), TIMER_DEFERRABLE)
81 .function = (_function), \
82 .expires = (_expires), \
83 .data = (_data), \
84 .base = TBASE_MAKE_DEFERRED(&boot_tvec_bases), \
85 __TIMER_LOCKDEP_MAP_INITIALIZER( \
86 __FILE__ ":" __stringify(__LINE__)) \
87 }
88 81
89#define DEFINE_TIMER(_name, _function, _expires, _data) \ 82#define DEFINE_TIMER(_name, _function, _expires, _data) \
90 struct timer_list _name = \ 83 struct timer_list _name = \
91 TIMER_INITIALIZER(_function, _expires, _data) 84 TIMER_INITIALIZER(_function, _expires, _data)
92 85
93void init_timer_key(struct timer_list *timer, 86void init_timer_key(struct timer_list *timer, unsigned int flags,
94 const char *name, 87 const char *name, struct lock_class_key *key);
95 struct lock_class_key *key);
96void init_timer_deferrable_key(struct timer_list *timer,
97 const char *name,
98 struct lock_class_key *key);
99 88
100#ifdef CONFIG_DEBUG_OBJECTS_TIMERS 89#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
101extern void init_timer_on_stack_key(struct timer_list *timer, 90extern void init_timer_on_stack_key(struct timer_list *timer,
102 const char *name, 91 unsigned int flags, const char *name,
103 struct lock_class_key *key); 92 struct lock_class_key *key);
104extern void destroy_timer_on_stack(struct timer_list *timer); 93extern void destroy_timer_on_stack(struct timer_list *timer);
105#else 94#else
106static inline void destroy_timer_on_stack(struct timer_list *timer) { } 95static inline void destroy_timer_on_stack(struct timer_list *timer) { }
107static inline void init_timer_on_stack_key(struct timer_list *timer, 96static inline void init_timer_on_stack_key(struct timer_list *timer,
108 const char *name, 97 unsigned int flags, const char *name,
109 struct lock_class_key *key) 98 struct lock_class_key *key)
110{ 99{
111 init_timer_key(timer, name, key); 100 init_timer_key(timer, flags, name, key);
112} 101}
113#endif 102#endif
114 103
115#ifdef CONFIG_LOCKDEP 104#ifdef CONFIG_LOCKDEP
116#define init_timer(timer) \ 105#define __init_timer(_timer, _flags) \
117 do { \ 106 do { \
118 static struct lock_class_key __key; \ 107 static struct lock_class_key __key; \
119 init_timer_key((timer), #timer, &__key); \ 108 init_timer_key((_timer), (_flags), #_timer, &__key); \
120 } while (0) 109 } while (0)
121 110
122#define init_timer_deferrable(timer) \ 111#define __init_timer_on_stack(_timer, _flags) \
123 do { \ 112 do { \
124 static struct lock_class_key __key; \ 113 static struct lock_class_key __key; \
125 init_timer_deferrable_key((timer), #timer, &__key); \ 114 init_timer_on_stack_key((_timer), (_flags), #_timer, &__key); \
126 } while (0) 115 } while (0)
116#else
117#define __init_timer(_timer, _flags) \
118 init_timer_key((_timer), (_flags), NULL, NULL)
119#define __init_timer_on_stack(_timer, _flags) \
120 init_timer_on_stack_key((_timer), (_flags), NULL, NULL)
121#endif
127 122
123#define init_timer(timer) \
124 __init_timer((timer), 0)
125#define init_timer_deferrable(timer) \
126 __init_timer((timer), TIMER_DEFERRABLE)
128#define init_timer_on_stack(timer) \ 127#define init_timer_on_stack(timer) \
128 __init_timer_on_stack((timer), 0)
129
130#define __setup_timer(_timer, _fn, _data, _flags) \
129 do { \ 131 do { \
130 static struct lock_class_key __key; \ 132 __init_timer((_timer), (_flags)); \
131 init_timer_on_stack_key((timer), #timer, &__key); \ 133 (_timer)->function = (_fn); \
134 (_timer)->data = (_data); \
132 } while (0) 135 } while (0)
133 136
134#define setup_timer(timer, fn, data) \ 137#define __setup_timer_on_stack(_timer, _fn, _data, _flags) \
135 do { \ 138 do { \
136 static struct lock_class_key __key; \ 139 __init_timer_on_stack((_timer), (_flags)); \
137 setup_timer_key((timer), #timer, &__key, (fn), (data));\ 140 (_timer)->function = (_fn); \
141 (_timer)->data = (_data); \
138 } while (0) 142 } while (0)
139 143
144#define setup_timer(timer, fn, data) \
145 __setup_timer((timer), (fn), (data), 0)
140#define setup_timer_on_stack(timer, fn, data) \ 146#define setup_timer_on_stack(timer, fn, data) \
141 do { \ 147 __setup_timer_on_stack((timer), (fn), (data), 0)
142 static struct lock_class_key __key; \
143 setup_timer_on_stack_key((timer), #timer, &__key, \
144 (fn), (data)); \
145 } while (0)
146#define setup_deferrable_timer_on_stack(timer, fn, data) \ 148#define setup_deferrable_timer_on_stack(timer, fn, data) \
147 do { \ 149 __setup_timer_on_stack((timer), (fn), (data), TIMER_DEFERRABLE)
148 static struct lock_class_key __key; \
149 setup_deferrable_timer_on_stack_key((timer), #timer, \
150 &__key, (fn), \
151 (data)); \
152 } while (0)
153#else
154#define init_timer(timer)\
155 init_timer_key((timer), NULL, NULL)
156#define init_timer_deferrable(timer)\
157 init_timer_deferrable_key((timer), NULL, NULL)
158#define init_timer_on_stack(timer)\
159 init_timer_on_stack_key((timer), NULL, NULL)
160#define setup_timer(timer, fn, data)\
161 setup_timer_key((timer), NULL, NULL, (fn), (data))
162#define setup_timer_on_stack(timer, fn, data)\
163 setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data))
164#define setup_deferrable_timer_on_stack(timer, fn, data)\
165 setup_deferrable_timer_on_stack_key((timer), NULL, NULL, (fn), (data))
166#endif
167
168static inline void setup_timer_key(struct timer_list * timer,
169 const char *name,
170 struct lock_class_key *key,
171 void (*function)(unsigned long),
172 unsigned long data)
173{
174 timer->function = function;
175 timer->data = data;
176 init_timer_key(timer, name, key);
177}
178
179static inline void setup_timer_on_stack_key(struct timer_list *timer,
180 const char *name,
181 struct lock_class_key *key,
182 void (*function)(unsigned long),
183 unsigned long data)
184{
185 timer->function = function;
186 timer->data = data;
187 init_timer_on_stack_key(timer, name, key);
188}
189
190extern void setup_deferrable_timer_on_stack_key(struct timer_list *timer,
191 const char *name,
192 struct lock_class_key *key,
193 void (*function)(unsigned long),
194 unsigned long data);
195 150
196/** 151/**
197 * timer_pending - is a timer pending? 152 * timer_pending - is a timer pending?