Added workaround for compilers/platforms that don't support TLS specifier.

This commit is contained in:
Branimir Karadžić 2015-09-13 13:24:14 -07:00
parent 2c3e6867d7
commit 344bacab7c
2 changed files with 52 additions and 8 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@
.git .git
.svn .svn
tags tags
.gdb_history

View file

@ -9,7 +9,7 @@ namespace bgfx
{ {
#define BGFX_MAIN_THREAD_MAGIC UINT32_C(0x78666762) #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() \ # define BGFX_CHECK_MAIN_THREAD() \
BX_CHECK(NULL != s_ctx, "Library is not initialized yet."); \ BX_CHECK(NULL != s_ctx, "Library is not initialized yet."); \
BX_CHECK(BGFX_MAIN_THREAD_MAGIC == s_threadIndex, "Must be called from main thread.") BX_CHECK(BGFX_MAIN_THREAD_MAGIC == s_threadIndex, "Must be called from main thread.")
@ -200,7 +200,50 @@ namespace bgfx
Caps g_caps; 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 Context* s_ctx = NULL;
static bool s_renderFrameCalled = false; static bool s_renderFrameCalled = false;
PlatformData g_platformData; PlatformData g_platformData;