mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-18 13:03:06 +01:00
Added TLS support.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "bx.h"
|
||||
#include "allocator.h"
|
||||
#include "debug.h"
|
||||
|
||||
namespace bx
|
||||
{
|
||||
@@ -17,7 +18,7 @@ namespace bx
|
||||
public:
|
||||
static const uint16_t invalid = 0xffff;
|
||||
|
||||
HandleAllocT()
|
||||
BX_NO_INLINE HandleAllocT()
|
||||
: m_numHandles(0)
|
||||
{
|
||||
for (uint16_t ii = 0; ii < MaxHandlesT; ++ii)
|
||||
|
||||
@@ -154,6 +154,69 @@ namespace bx
|
||||
bool m_running;
|
||||
};
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
class TlsData
|
||||
{
|
||||
public:
|
||||
TlsData()
|
||||
{
|
||||
m_id = TlsAlloc();
|
||||
BX_CHECK(TLS_OUT_OF_INDEXES != m_id, "Failed to allocated TLS index (err: 0x%08x).", GetLastError() );
|
||||
}
|
||||
|
||||
~TlsData()
|
||||
{
|
||||
BOOL result = TlsFree(m_id);
|
||||
BX_CHECK(0 != result, "Failed to free TLS index (err: 0x%08x).", GetLastError() ); BX_UNUSED(result);
|
||||
}
|
||||
|
||||
void* get() const
|
||||
{
|
||||
return TlsGetValue(m_id);
|
||||
}
|
||||
|
||||
void set(void* _ptr)
|
||||
{
|
||||
TlsSetValue(m_id, _ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_id;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class TlsData
|
||||
{
|
||||
public:
|
||||
TlsData()
|
||||
{
|
||||
int result = pthread_key_create(&m_id, NULL);
|
||||
BX_CHECK(0 == result, "pthread_key_create failed %d.", result); BX_UNUSED(result);
|
||||
}
|
||||
|
||||
~TlsData()
|
||||
{
|
||||
int result = pthread_key_delete(m_id);
|
||||
BX_CHECK(0 == result, "pthread_key_delete failed %d.", result); BX_UNUSED(result);
|
||||
}
|
||||
|
||||
void* get() const
|
||||
{
|
||||
return pthread_getspecific(m_id);
|
||||
}
|
||||
|
||||
void set(void* _ptr)
|
||||
{
|
||||
int result = pthread_setspecific(m_id, _ptr);
|
||||
BX_CHECK(0 == result, "pthread_setspecific failed %d.", result); BX_UNUSED(result);
|
||||
}
|
||||
|
||||
private:
|
||||
pthread_key_t m_id;
|
||||
};
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
|
||||
} // namespace bx
|
||||
|
||||
#endif // __BX_THREAD_H__
|
||||
|
||||
Reference in New Issue
Block a user