summary refs log tree commit diff stats
path: root/lib/nimbase.h
diff options
context:
space:
mode:
authorAnatoly Galiulin <vega@eldis.ru>2016-03-01 17:23:10 +0600
committerAnatoly Galiulin <vega@eldis.ru>2016-03-01 17:23:10 +0600
commit1a1710c3ec688e5d3975561334801b86f47288f3 (patch)
tree03f38aed2ec2715cb92e6626702d0733dc90edb0 /lib/nimbase.h
parent232d042731589335f65ca3b5d6b41faf2df42ba4 (diff)
downloadNim-1a1710c3ec688e5d3975561334801b86f47288f3.tar.gz
Fixed NIM_THREADVAR definition in nimbase.h
Diffstat (limited to 'lib/nimbase.h')
-rw-r--r--lib/nimbase.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/nimbase.h b/lib/nimbase.h
index 40ea6c66a..266b84b09 100644
--- a/lib/nimbase.h
+++ b/lib/nimbase.h
@@ -91,10 +91,25 @@ __clang__
 #  define NIM_CONST  const
 #endif
 
-#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
-#  define NIM_THREADVAR __declspec(thread)
-#else
+/*
+  NIM_THREADVAR declaration based on
+  http://stackoverflow.com/questions/18298280/how-to-declare-a-variable-as-thread-local-portably
+*/
+#if __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__
+#  define NIM_THREADVAR _Thread_local
+#elif defined _WIN32 && ( \
+       defined _MSC_VER || \
+       defined __ICL || \
+       defined __DMC__ || \
+       defined __BORLANDC__ )
+#  define NIM_THREADVAR __declspec(thread) 
+/* note that ICC (linux) and Clang are covered by __GNUC__ */
+#elif defined __GNUC__ || \
+       defined __SUNPRO_C || \
+       defined __xlC__
 #  define NIM_THREADVAR __thread
+#else
+#  error "Cannot define NIM_THREADVAR"
 #endif
 
 /* --------------- how int64 constants should be declared: ----------- */