lkml.org 
[lkml]   [2018]   [Apr]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 35/45] C++: Fix static_branch_likely/unlikely()
From
Date
Fix static_branch_likely/unlikely() to use C++ function overloading to
simplify the source.

Signed-off-by: David Howells <dhowells@redhat.com>
---

include/linux/jump_label.h | 41 +++++++++++++++++++----------------------
1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 2168cc6b8b30..25683b1764bf 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -387,29 +387,26 @@ extern bool ____wrong_branch_error(void);
* See jump_label_type() / jump_label_init_type().
*/

-#define static_branch_likely(x) \
-({ \
- bool branch; \
- if (__builtin_types_compatible_p(typeof(*x), struct static_key_true)) \
- branch = !arch_static_branch(&(x)->key, true); \
- else if (__builtin_types_compatible_p(typeof(*x), struct static_key_false)) \
- branch = !arch_static_branch_jump(&(x)->key, true); \
- else \
- branch = ____wrong_branch_error(); \
- likely(branch); \
-})

-#define static_branch_unlikely(x) \
-({ \
- bool branch; \
- if (__builtin_types_compatible_p(typeof(*x), struct static_key_true)) \
- branch = arch_static_branch_jump(&(x)->key, false); \
- else if (__builtin_types_compatible_p(typeof(*x), struct static_key_false)) \
- branch = arch_static_branch(&(x)->key, false); \
- else \
- branch = ____wrong_branch_error(); \
- unlikely(branch); \
-})
+static inline bool static_branch_likely(struct static_key_true *x)
+{
+ return likely(!arch_static_branch(&(x)->key, true));
+}
+
+static inline bool static_branch_likely(struct static_key_false *x)
+{
+ return likely(!arch_static_branch_jump(&(x)->key, true));
+}
+
+static inline bool static_branch_unlikely(struct static_key_true *x)
+{
+ return unlikely(!arch_static_branch_jump(&(x)->key, true));
+}
+
+static inline bool static_branch_unlikely(struct static_key_false *x)
+{
+ return unlikely(!arch_static_branch(&(x)->key, true));
+}

#else /* !HAVE_JUMP_LABEL */

\
 
 \ /
  Last update: 2018-04-01 22:46    [W:0.232 / U:1.972 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site