diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-02-05 07:45:43 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-02-05 07:52:29 -0500 |
commit | f036be96dd9ce442ffb9ab33e3c165f5178815c0 (patch) | |
tree | c60c39f895bb93ac0000de7772e89a0b6663954b /include | |
parent | eda58a85ec3fc05855a26654d97a2b53f0e715b9 (diff) |
printk: introduce printk_once()
This pattern shows up frequently in the kernel:
static int once = 1;
...
if (once) {
once = 0;
printk(KERN_ERR "message\n");
}
...
So add a printk_once() helper macro that reduces this to a single line
of:
printk_once(KERN_ERR "message\n");
It works analogously to WARN_ONCE() & friends. (We use a macro not
an inline because vararg expansion in inlines looks awkward and the
macro is simple enough.)
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/kernel.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 343df9ef2412..3c183d9864ae 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -242,6 +242,19 @@ extern struct ratelimit_state printk_ratelimit_state; | |||
242 | extern int printk_ratelimit(void); | 242 | extern int printk_ratelimit(void); |
243 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, | 243 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
244 | unsigned int interval_msec); | 244 | unsigned int interval_msec); |
245 | |||
246 | /* | ||
247 | * Print a one-time message (analogous to WARN_ONCE() et al): | ||
248 | */ | ||
249 | #define printk_once(x...) ({ \ | ||
250 | static int __print_once = 1; \ | ||
251 | \ | ||
252 | if (__print_once) { \ | ||
253 | __print_once = 0; \ | ||
254 | printk(x); \ | ||
255 | } \ | ||
256 | }) | ||
257 | |||
245 | #else | 258 | #else |
246 | static inline int vprintk(const char *s, va_list args) | 259 | static inline int vprintk(const char *s, va_list args) |
247 | __attribute__ ((format (printf, 1, 0))); | 260 | __attribute__ ((format (printf, 1, 0))); |
@@ -253,6 +266,10 @@ static inline int printk_ratelimit(void) { return 0; } | |||
253 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ | 266 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ |
254 | unsigned int interval_msec) \ | 267 | unsigned int interval_msec) \ |
255 | { return false; } | 268 | { return false; } |
269 | |||
270 | /* No effect, but we still get type checking even in the !PRINTK case: */ | ||
271 | #define printk_once(x...) printk(x) | ||
272 | |||
256 | #endif | 273 | #endif |
257 | 274 | ||
258 | extern int printk_needs_cpu(int cpu); | 275 | extern int printk_needs_cpu(int cpu); |