chiark / gitweb /
__thread --> thread_local for C11 compat
[elogind.git] / src / shared / macro.h
index 9f5f51cb13e2eff079c667e94785cf07dd27de06..2b5b3fdfe0038e3c74e419441f7621f68aad9d29 100644 (file)
@@ -153,10 +153,12 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
 #define assert_cc(expr) struct UNIQUE(_assert_struct_) { char x[(expr) ? 0 : -1]; };
 #endif
 
-#define assert_return(expr, r)                    \
-        do {                                      \
-                if (_unlikely_(!(expr)))          \
-                        return (r);               \
+#define assert_return(expr, r)                                          \
+        do {                                                            \
+                if (_unlikely_(!(expr))) {                              \
+                        log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+                        return (r);                                     \
+                }                                                       \
         } while (false)
 
 #define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
@@ -285,4 +287,30 @@ do {                                                                    \
 #define SET_FLAG(v, flag, b) \
         (v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
 
+#define IN_SET(x, ...)                                                  \
+        ({                                                              \
+                const typeof(x) _x = (x);                               \
+                unsigned _i;                                            \
+                bool _found = false;                                    \
+                for (_i = 0; _i < sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
+                        if (((const typeof(_x)[]) { __VA_ARGS__ })[_i] == _x) { \
+                                _found = true;                          \
+                                break;                                  \
+                        }                                               \
+                _found;                                                 \
+        })
+
+/* Define C11 thread_local attribute even on older compilers */
+#ifndef thread_local
+/*
+ * Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
+ * see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769
+ */
+#if __STDC_VERSION__ >= 201112L && !(defined(__STDC_NO_THREADS__) || (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
+#define thread_local _Thread_local
+#else
+#define thread_local __thread
+#endif
+#endif
+
 #include "log.h"