From: José Fonseca Date: Wed, 24 Oct 2012 13:58:26 +0000 (+0100) Subject: Use compiler TLS support. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=39a9f3650233206061134772417bfada16cd07be Use compiler TLS support. Seems to work OK everywhere, provided one uses recent compiler versions. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 09633c1..f019049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 () diff --git a/common/os_thread.hpp b/common/os_thread.hpp index 3aeeee4..6c0b488 100644 --- a/common/os_thread.hpp +++ b/common/os_thread.hpp @@ -39,6 +39,24 @@ #include #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 { diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp index 319a2cb..d4b0817 100644 --- a/retrace/glretrace_ws.cpp +++ b/retrace/glretrace_ws.cpp @@ -122,14 +122,14 @@ createContext(Context *shareContext) { } -static os::thread_specific_ptr +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; }