mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-17 19:42:27 -05:00
Added workaround for compilers/platforms that don't support TLS specifier.
This commit is contained in:
parent
2c3e6867d7
commit
344bacab7c
2 changed files with 52 additions and 8 deletions
13
.gitignore
vendored
13
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
||||||
.build
|
.build
|
||||||
.debug
|
.debug
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.git
|
.git
|
||||||
.svn
|
.svn
|
||||||
tags
|
tags
|
||||||
|
.gdb_history
|
||||||
|
|
47
src/bgfx.cpp
47
src/bgfx.cpp
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue