[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1381870252-5430-2-git-send-email-fweisbec@gmail.com>
Date: Tue, 15 Oct 2013 22:50:50 +0200
From: Frederic Weisbecker <fweisbec@...il.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
Frederic Weisbecker <fweisbec@...il.com>,
Steven Rostedt <rostedt@...dmis.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
"H. Peter Anvin" <hpa@...or.com>,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>,
Liu Chuansheng <chuansheng.liu@...el.com>,
Ingo Molnar <mingo@...nel.org>
Subject: [PATCH 1/3] core: New macro to execute code only once
Introduce DO_COND(), DO_ONCE() and DO_ONCE_COND(). These
macros should ease the consolidation of CPP code when
it is deemed to be executed only once and/or after a
condition is verified. This incluse printk_once, WARN_ON,
WARN_ON_ONCE, etc...
Signed-off-by: Frederic Weisbecker <fweisbec@...il.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: H. Peter Anvin <hpa@...or.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Liu Chuansheng <chuansheng.liu@...el.com>
Cc: Ingo Molnar <mingo@...nel.org>
---
include/linux/once.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
create mode 100644 include/linux/once.h
diff --git a/include/linux/once.h b/include/linux/once.h
new file mode 100644
index 0000000..9399f37
--- /dev/null
+++ b/include/linux/once.h
@@ -0,0 +1,26 @@
+#ifndef _LINUX_ONCE_H
+#define _LINUX_ONCE_H
+
+#include <linux/compiler.h>
+
+#define DO_COND(condition, to_do) ({ \
+ int __ret = !!(condition); \
+ if (unlikely(__ret)) { \
+ to_do; \
+ } \
+ unlikely(__ret); \
+})
+
+#define DO_ONCE(to_do) ({ \
+ static bool __done; \
+ \
+ if (!__done) { \
+ __done = true; \
+ to_do; \
+ } \
+})
+
+#define DO_ONCE_COND(condition, to_do) \
+ DO_COND(condition, DO_ONCE(to_do))
+
+#endif /* _LINUX_ONCE_H */
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists