Merge pull request #2348 from ben-clayton/thread-local
Simplify PoolAlloc by using `thread_local`
This commit is contained in:
commit
11fa4d0d56
4 changed files with 16 additions and 150 deletions
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
namespace glslang {
|
||||
|
||||
bool InitializePoolIndex();
|
||||
inline bool InitializePoolIndex() { return true; } // DEPRECATED: No need to call
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
|
|
|
|||
|
|
@ -35,34 +35,28 @@
|
|||
#include "../Include/Common.h"
|
||||
#include "../Include/PoolAlloc.h"
|
||||
|
||||
#include "../Include/InitializeGlobals.h"
|
||||
#include "../OSDependent/osinclude.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// Process-wide TLS index
|
||||
OS_TLSIndex PoolIndex;
|
||||
namespace {
|
||||
thread_local TPoolAllocator* threadPoolAllocator = nullptr;
|
||||
|
||||
TPoolAllocator* GetDefaultThreadPoolAllocator()
|
||||
{
|
||||
thread_local TPoolAllocator defaultAllocator;
|
||||
return &defaultAllocator;
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
// Return the thread-specific current pool.
|
||||
TPoolAllocator& GetThreadPoolAllocator()
|
||||
{
|
||||
return *static_cast<TPoolAllocator*>(OS_GetTLSValue(PoolIndex));
|
||||
return *(threadPoolAllocator ? threadPoolAllocator : GetDefaultThreadPoolAllocator());
|
||||
}
|
||||
|
||||
// Set the thread-specific current pool.
|
||||
void SetThreadPoolAllocator(TPoolAllocator* poolAllocator)
|
||||
{
|
||||
OS_SetTLSValue(PoolIndex, 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;
|
||||
threadPoolAllocator = poolAllocator;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue