Added cds_likely/cds_unlikely macro
authorkhizmax <libcds.dev@gmail.com>
Sat, 2 Jul 2016 15:05:09 +0000 (18:05 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 2 Jul 2016 15:05:09 +0000 (18:05 +0300)
cds/compiler/clang/defs.h
cds/compiler/defs.h
cds/compiler/gcc/defs.h

index 4a84e3a..7d27135 100644 (file)
 #define CDS_DATA_ALIGNMENT(n)   __attribute__ ((aligned (n)))
 
 
+// likely/unlikely
+
+#define cds_likely( expr )   __builtin_expect( !!( expr ), 1 )
+#define cds_unlikely( expr ) __builtin_expect( !!( expr ), 0 )
+
 #include <cds/compiler/gcc/compiler_barriers.h>
 
 #endif // #ifndef CDSLIB_COMPILER_GCC_DEFS_H
index 0e663c8..3470643 100644 (file)
 #   define CDS_EXPORT_API
 #endif
 
+#ifndef cds_likely
+#   define cds_likely( expr )   expr
+#   define cds_unlikely( expr ) expr
+#endif
+
 // Features
 #include <cds/compiler/feature_tsan.h>
 
index e3c91e7..a6028cc 100644 (file)
 #   define CDS_DEPRECATED( reason ) __attribute__((deprecated( reason )))
 #endif
 
+// likely/unlikely
+
+#define cds_likely( expr )   __builtin_expect( !!( expr ), 1 )
+#define cds_unlikely( expr ) __builtin_expect( !!( expr ), 0 )
+
 #include <cds/compiler/gcc/compiler_barriers.h>
 
 #endif // #ifndef CDSLIB_COMPILER_GCC_DEFS_H