From 8917aeafc32928b4bcbd668a3f20f5dae101c8d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 23 Apr 2013 10:12:12 +0100 Subject: [PATCH] os: Bring back the compiler TLS check. Seems better than fiddling with pre-defined macros. --- CMakeLists.txt | 13 +++++++++++++ common/os_thread.hpp | 14 ++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa96903..3b45bae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/common/os_thread.hpp b/common/os_thread.hpp index fb340e1..51ac54f 100644 --- a/common/os_thread.hpp +++ b/common/os_thread.hpp @@ -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 @@ -54,14 +53,9 @@ * - 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 -- 2.45.2