Implement likely/unlikely ifdefs
authorEtienne Bergeron <etienneb@google.com>
Tue, 2 Apr 2013 23:24:22 +0000 (19:24 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Apr 2013 23:30:28 +0000 (19:30 -0400)
- don't redefine likely/unlikely on compilers already defining them,
- don't use builtins on compilers not supporting them.

Signed-off-by: Etienne Bergeron <etienneb@google.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/babeltrace/babeltrace-internal.h

index 339c1e7c115758190eacd0dadbbe7a2ad621de52..0d06ed58827e3ea1184c7df72df8efac8a67bea9 100644 (file)
@@ -91,8 +91,21 @@ extern int babeltrace_verbose, babeltrace_debug;
 #define fprintfn_warning(fp, node, fmt, args...)                       \
        _bt_printfl(fp, "warning", (node)->lineno, fmt, ## args)
 
-#define likely(x)      __builtin_expect(!!(x), 1)
-#define unlikely(x)    __builtin_expect(!!(x), 0)
+#ifndef likely
+# ifdef __GNUC__
+#  define likely(x)      __builtin_expect(!!(x), 1)
+# else
+#  define likely(x)      (!!(x))
+# endif
+#endif
+
+#ifndef unlikely
+# ifdef __GNUC__
+#  define unlikely(x)    __builtin_expect(!!(x), 0)
+# else
+#  define unlikely(x)    (!!(x))
+# endif
+#endif
 
 /*
  * BT_HIDDEN: set the hidden attribute for internal functions
This page took 0.025154 seconds and 4 git commands to generate.