]> git.cworth.org Git - apitrace/commitdiff
Use compiler TLS support.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 24 Oct 2012 13:58:26 +0000 (14:58 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 24 Oct 2012 13:58:26 +0000 (14:58 +0100)
Seems to work OK everywhere, provided one uses recent compiler versions.

CMakeLists.txt
common/os_thread.hpp
retrace/glretrace_ws.cpp

index 09633c14f98a08fe2cf61f6dc2e45f4bad782b21..f019049e3f561e9f395ee23cfc481621fa443da2 100644 (file)
@@ -35,11 +35,17 @@ set (ENABLE_EGL true CACHE BOOL "Enable EGL support.")
 # Find dependencies
 
 # Ensure __thread is support
-if (APPLE)
+if (NOT MSVC)
     include (CheckCXXSourceCompiles)
     check_cxx_source_compiles("__thread int i; int main() { return 0; }" HAVE_COMPILER_TLS)
     if (NOT HAVE_COMPILER_TLS)
-        message (FATAL_ERROR "C++ compiler does not support __thread keyword. Please install XCode 4.5 or higher.")
+        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 ()
 
index 3aeeee4849551e360bcc4db44335e9251603d415..6c0b488c0152474a031a82839b0c767777714fdd 100644 (file)
 #include <pthread.h>
 #endif
 
+
+/**
+ * Compiler TLS.
+ *
+ * See also:
+ * - 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"
+#endif
+
+
 namespace os {
 
 
index 319a2cbe80e65cfbb6b701c8c0d1b3f23c5dcd9c..d4b0817bfdf0b1852a619a81e41926eadfb73023 100644 (file)
@@ -122,14 +122,14 @@ createContext(Context *shareContext) {
 }
 
 
-static os::thread_specific_ptr<Context>
+static thread_specific Context *
 currentContextPtr;
 
 
 bool
 makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
 {
-    Context *currentContext = currentContextPtr.release();
+    Context *currentContext = currentContextPtr;
     glws::Drawable *currentDrawable = currentContext ? currentContext->drawable : NULL;
 
     if (drawable == currentDrawable && context == currentContext) {
@@ -159,7 +159,7 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
 
     if (drawable && context) {
         context->drawable = drawable;
-        currentContextPtr.reset(context);
+        currentContextPtr = context;
         
         if (!context->used) {
             initContext();
@@ -173,7 +173,7 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
 
 Context *
 getCurrentContext(void) {
-    return currentContextPtr.get();
+    return currentContextPtr;
 }