diff --git a/.gitignore b/.gitignore index 43c5713f..3f3804ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -.build -.debug -.DS_Store -.git -.svn -tags +.build +.debug +.DS_Store +.git +.svn +tags +.gdb_history diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 68dba688..d66826f4 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -9,7 +9,7 @@ namespace bgfx { #define BGFX_MAIN_THREAD_MAGIC UINT32_C(0x78666762) -#if BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS +#if BGFX_CONFIG_MULTITHREADED # define BGFX_CHECK_MAIN_THREAD() \ BX_CHECK(NULL != s_ctx, "Library is not initialized yet."); \ BX_CHECK(BGFX_MAIN_THREAD_MAGIC == s_threadIndex, "Must be called from main thread.") @@ -200,7 +200,50 @@ namespace bgfx Caps g_caps; - static BX_THREAD uint32_t s_threadIndex = 0; +#if !defined(BX_THREAD_LOCAL) + class ThreadData + { + BX_CLASS(ThreadData + , NO_COPY + , NO_ASSIGNMENT + ); + + public: + ThreadData(uintptr_t _rhs) + { + union { uintptr_t ui; void* ptr; } cast = { _rhs }; + m_tls.set(cast.ptr); + } + + operator uintptr_t() const + { + union { uintptr_t ui; void* ptr; } cast; + cast.ptr = m_tls.get(); + return cast.ui; + } + + uintptr_t operator=(uintptr_t _rhs) + { + union { uintptr_t ui; void* ptr; } cast = { _rhs }; + m_tls.set(cast.ptr); + return _rhs; + } + + bool operator==(uintptr_t _rhs) + { + uintptr_t lhs = *this; + return lhs == _rhs; + } + + private: + bx::TlsData m_tls; + }; + + static ThreadData s_threadIndex(0); +#else + static BX_THREAD_LOCAL uint32_t s_threadIndex(0); +#endif + static Context* s_ctx = NULL; static bool s_renderFrameCalled = false; PlatformData g_platformData;