Seems to work OK everywhere, provided one uses recent compiler versions.
# 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 ()
#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 {
}
-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) {
if (drawable && context) {
context->drawable = drawable;
- currentContextPtr.reset(context);
+ currentContextPtr = context;
if (!context->used) {
initContext();
Context *
getCurrentContext(void) {
- return currentContextPtr.get();
+ return currentContextPtr;
}