Support to multi-threading and pthread interface (POSIX.1-2008) (#23)
[lunaix-os.git] / lunaix-os / includes / lunaix / compiler.h
index 3ee6fa0ebff472b42afae3a14ab2bdda96b51813..c3eab586a9c4f7494c457cfc04f2dc733c052d65 100644 (file)
@@ -1,14 +1,16 @@
 #ifndef __LUNAIX_COMPILER_H
 #define __LUNAIX_COMPILER_H
 
 #ifndef __LUNAIX_COMPILER_H
 #define __LUNAIX_COMPILER_H
 
-#define likely(x) __builtin_expect((x), 1)
-#define unlikely(x) __builtin_expect((x), 0)
+#define likely(x) __builtin_expect(!!(x), 1)
+#define unlikely(x) __builtin_expect(!!(x), 0)
 
 #define weak_alias(name) __attribute__((weak, alias(name)))
 #define weak __attribute__((weak))
 #define noret __attribute__((noreturn))
 #define optimize(opt) __attribute__((optimize(opt)))
 #define must_inline __attribute__((always_inline))
 
 #define weak_alias(name) __attribute__((weak, alias(name)))
 #define weak __attribute__((weak))
 #define noret __attribute__((noreturn))
 #define optimize(opt) __attribute__((optimize(opt)))
 #define must_inline __attribute__((always_inline))
+#define must_emit __attribute__((used))
+#define unreachable __builtin_unreachable()
 
 #define clz(bits) __builtin_clz(bits)
 #define sadd_overflow(a, b, of) __builtin_sadd_overflow(a, b, of)
 
 #define clz(bits) __builtin_clz(bits)
 #define sadd_overflow(a, b, of) __builtin_sadd_overflow(a, b, of)
 #define compact __attribute__((packed))
 #define align(v) __attribute__((aligned (v)))
 
 #define compact __attribute__((packed))
 #define align(v) __attribute__((aligned (v)))
 
+#define export_symbol(domain, namespace, symbol)\
+    typeof(symbol)* must_emit __SYMEXPORT_Z##domain##_N##namespace##_S##symbol = &(symbol)
+
 inline static void noret
 spin()
 {
     volatile int __infloop = 1;
     while (__infloop)
         ;
 inline static void noret
 spin()
 {
     volatile int __infloop = 1;
     while (__infloop)
         ;
-    __builtin_unreachable();
+    unreachable;
 }
 
 #endif /* __LUNAIX_COMPILER_H */
 }
 
 #endif /* __LUNAIX_COMPILER_H */