Commit a3845240 by Ben Clayton

Simplify PoolAlloc with use of thread_local.

glslang is using C++ 11, which has first class support for variables of the `thread_local` storage class. By dropping the use of the `OS_[GS]etTLSValue`, we can simplify the logic, and have it support a thread-local default allocator if none is provided. Issue: #2346
parent b99a6a72
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
namespace glslang { namespace glslang {
bool InitializePoolIndex(); inline bool InitializePoolIndex() { return true; } // DEPRECATED: No need to call
} // end namespace glslang } // end namespace glslang
......
...@@ -35,34 +35,28 @@ ...@@ -35,34 +35,28 @@
#include "../Include/Common.h" #include "../Include/Common.h"
#include "../Include/PoolAlloc.h" #include "../Include/PoolAlloc.h"
#include "../Include/InitializeGlobals.h"
#include "../OSDependent/osinclude.h"
namespace glslang { namespace glslang {
// Process-wide TLS index namespace {
OS_TLSIndex PoolIndex; thread_local TPoolAllocator* threadPoolAllocator = nullptr;
TPoolAllocator* GetDefaultThreadPoolAllocator()
{
thread_local TPoolAllocator defaultAllocator;
return &defaultAllocator;
}
} // anonymous namespace
// Return the thread-specific current pool. // Return the thread-specific current pool.
TPoolAllocator& GetThreadPoolAllocator() TPoolAllocator& GetThreadPoolAllocator()
{ {
return *static_cast<TPoolAllocator*>(OS_GetTLSValue(PoolIndex)); return *(threadPoolAllocator ? threadPoolAllocator : GetDefaultThreadPoolAllocator());
} }
// Set the thread-specific current pool. // Set the thread-specific current pool.
void SetThreadPoolAllocator(TPoolAllocator* poolAllocator) void SetThreadPoolAllocator(TPoolAllocator* poolAllocator)
{ {
OS_SetTLSValue(PoolIndex, poolAllocator); threadPoolAllocator = poolAllocator;
}
// Process-wide set up of the TLS pool storage.
bool InitializePoolIndex()
{
// Allocate a TLS index.
if ((PoolIndex = OS_AllocTLSIndex()) == OS_INVALID_TLS_INDEX)
return false;
return true;
} }
// //
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment