summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt15
-rw-r--r--common/os_thread.hpp20
-rw-r--r--common/trace_writer_local.cpp17
-rw-r--r--retrace/glretrace_ws.cpp2
-rw-r--r--wrappers/gltrace_state.cpp2
5 files changed, 26 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9394282c..aa969035 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,21 +34,6 @@ set (ENABLE_EGL true CACHE BOOL "Enable EGL support.")
##############################################################################
# Find dependencies
-# Ensure __thread is support
-if (NOT MSVC)
- include (CheckCXXSourceCompiles)
- check_cxx_source_compiles("__thread int i; int main() { return 0; }" HAVE_COMPILER_TLS)
- if (NOT HAVE_COMPILER_TLS)
- if (APPLE)
- message (FATAL_ERROR "C++ compiler does not support __thread keyword. Please install XCode 4.5 or higher.")
- else (MINGW32)
- message (FATAL_ERROR "C++ compiler does not support __thread keyword. Please use MinGW g++ version 4.4 or higher")
- else ()
- message (FATAL_ERROR "C++ compiler does not support __thread keyword.")
- endif ()
- 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 da6e1064..fb340e16 100644
--- a/common/os_thread.hpp
+++ b/common/os_thread.hpp
@@ -40,6 +40,10 @@
#endif
+/*
+ * These features are not supported on Windows XP
+ */
+#define USE_WIN32_DECLSPEC_THREAD 0
#define USE_WIN32_CONDITION_VARIABLES 0
@@ -50,13 +54,15 @@
* - http://gcc.gnu.org/onlinedocs/gcc-4.6.3/gcc/Thread_002dLocal.html
* - http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx
*/
-#if defined(_MSC_VER)
-# define thread_specific __declspec(thread)
-#elif defined(__GNUC__)
-# define thread_specific __thread
-#else
-# define thread_specific
-# error "Unsupported compiler"
+#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)
+# define OS_THREAD_SPECIFIC_PTR(_type) os::thread_specific_ptr< _type >
#endif
diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp
index feb5c912..757e9c0f 100644
--- a/common/trace_writer_local.cpp
+++ b/common/trace_writer_local.cpp
@@ -128,8 +128,10 @@ LocalWriter::open(void) {
#endif
}
-static unsigned next_thread_num = 1;
-static thread_specific unsigned thread_num = 0;
+static uintptr_t next_thread_num = 1;
+
+static OS_THREAD_SPECIFIC_PTR(void)
+thread_num;
unsigned LocalWriter::beginEnter(const FunctionSig *sig) {
mutex.lock();
@@ -139,13 +141,16 @@ unsigned LocalWriter::beginEnter(const FunctionSig *sig) {
open();
}
- unsigned this_thread_num = thread_num;
+ // Although thread_num is a void *, we actually use it as a uintptr_t
+ uintptr_t this_thread_num =
+ reinterpret_cast<uintptr_t>(static_cast<void *>(thread_num));
if (!this_thread_num) {
- this_thread_num = thread_num = next_thread_num++;
+ this_thread_num = next_thread_num++;
+ thread_num = reinterpret_cast<void *>(this_thread_num);
}
- assert(thread_num > 0);
- unsigned thread_id = thread_num - 1;
+ assert(this_thread_num);
+ unsigned thread_id = this_thread_num - 1;
return Writer::beginEnter(sig, thread_id);
}
diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp
index ac03fcc9..94a0d931 100644
--- a/retrace/glretrace_ws.cpp
+++ b/retrace/glretrace_ws.cpp
@@ -131,7 +131,7 @@ Context::~Context()
}
-static thread_specific Context *
+static OS_THREAD_SPECIFIC_PTR(Context)
currentContextPtr;
diff --git a/wrappers/gltrace_state.cpp b/wrappers/gltrace_state.cpp
index 031b5cce..60eada60 100644
--- a/wrappers/gltrace_state.cpp
+++ b/wrappers/gltrace_state.cpp
@@ -57,7 +57,7 @@ public:
}
};
-static thread_specific ThreadState *thread_state;
+static OS_THREAD_SPECIFIC_PTR(ThreadState) thread_state;
static ThreadState *get_ts(void)
{