]> git.cworth.org Git - apitrace/commitdiff
os: Bring back the compiler TLS check.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 23 Apr 2013 09:12:12 +0000 (10:12 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Tue, 23 Apr 2013 13:07:02 +0000 (14:07 +0100)
Seems better than fiddling with pre-defined macros.

CMakeLists.txt
common/os_thread.hpp

index aa96903533e21fb8f3a142fc4d84401807ce271c..3b45baee831596e09c22e54ec78c5a42d83026cf 100644 (file)
@@ -34,6 +34,19 @@ set (ENABLE_EGL true CACHE BOOL "Enable EGL support.")
 ##############################################################################
 # Find dependencies
 
+# Check for compiler TLS support.  We don't use compiler TLS support on Windows
+# because, even if the compiler supports it, Windows XP does not support TLS on
+# DLLs.
+if (NOT WIN32)
+    include (CheckCXXSourceCompiles)
+    check_cxx_source_compiles("__thread int i; int main() { return 0; }" HAVE_COMPILER_TLS)
+    if (HAVE_COMPILER_TLS)
+        add_definitions (-DHAVE_COMPILER_TLS=__thread)
+    else ()
+        message (WARNING "C++ compiler does not support __thread keyword.")
+    endif ()
+endif ()
+
 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
 
 set (CMAKE_USE_PYTHON_VERSION 2.7 2.6)
index fb340e162c2401e4bc019326b9f44d413acab544..51ac54f3864d6ddf69b94d4413bd124e184c8707 100644 (file)
@@ -41,9 +41,8 @@
 
 
 /*
- * These features are not supported on Windows XP
+ * This feature is not supported on Windows XP
  */
-#define USE_WIN32_DECLSPEC_THREAD 0
 #define USE_WIN32_CONDITION_VARIABLES 0
 
 
  * - http://gcc.gnu.org/onlinedocs/gcc-4.6.3/gcc/Thread_002dLocal.html
  * - http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx
  */
-#if !defined(_WIN32) || USE_WIN32_DECLSPEC_THREAD
-#  if defined(_MSC_VER)
-#    define OS_THREAD_SPECIFIC_PTR(_type) __declspec(thread) _type *
-#  elif defined(__GNUC__)
-#    define OS_THREAD_SPECIFIC_PTR(_type) __thread _type *
-#  endif
-#endif
-#if !defined(OS_THREAD_SPECIFIC_PTR)
+#if defined(HAVE_COMPILER_TLS)
+#  define OS_THREAD_SPECIFIC_PTR(_type) HAVE_COMPILER_TLS _type *
+#else
 #  define OS_THREAD_SPECIFIC_PTR(_type) os::thread_specific_ptr< _type >
 #endif