瀏覽代碼

don't define thread-local variable when multithreading is disabled; required for OpenBSD

Julius Pfrommer 7 年之前
父節點
當前提交
5b91f643c4
共有 1 個文件被更改,包括 10 次插入8 次删除
  1. 10 8
      src/ua_util.h

+ 10 - 8
src/ua_util.h

@@ -19,16 +19,18 @@
     (type *)((uintptr_t)ptr - offsetof(type,member))
 
 /* Thread Local Storage */
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
-# define UA_THREAD_LOCAL _Thread_local /* C11 */
-#elif defined(__GNUC__)
-# define UA_THREAD_LOCAL __thread /* GNU extension */
-#elif defined(_MSC_VER)
-# define UA_THREAD_LOCAL __declspec(thread) /* MSVC extension */
+#ifdef UA_ENABLE_MULTITHREADING
+# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#  define UA_THREAD_LOCAL _Thread_local /* C11 */
+# elif defined(__GNUC__)
+#  define UA_THREAD_LOCAL __thread /* GNU extension */
+# elif defined(_MSC_VER)
+#  define UA_THREAD_LOCAL __declspec(thread) /* MSVC extension */
+# else
+#  error The compiler does not support thread-local variables.
+# endif
 #else
 # define UA_THREAD_LOCAL
-# warning The compiler does not allow thread-local variables. \
-  The library can be built, but will not be thread-safe.
 #endif
 
 /* Atomic Operations