Memory: Remove the need for per-thread tear down.

Make key objects using the memory pool own their own pool and delete it,
such that there is not generic per-thread pool to manage.
This commit is contained in:
John Kessenich 2017-11-12 23:12:57 -07:00
parent ff8e59f510
commit cb42541e51
7 changed files with 17 additions and 130 deletions

View file

@ -43,35 +43,16 @@ namespace glslang {
// Process-wide TLS index
OS_TLSIndex PoolIndex;
// Per-thread structure holding pool pointers.
struct TThreadMemoryPools
{
TPoolAllocator* threadPoolAllocator; // the current pool
TPoolAllocator* initialMemoryPool; // the original pool owned by this thread (this file), to be freed here as well
};
// Return the thread-specific pool pointers.
TThreadMemoryPools* GetThreadMemoryPools()
{
return static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));
}
// Set the thread-specific pool pointers.
void SetThreadMemoryPools(TThreadMemoryPools* pools)
{
OS_SetTLSValue(PoolIndex, pools);
}
// Return the thread-specific current pool.
TPoolAllocator& GetThreadPoolAllocator()
{
return *GetThreadMemoryPools()->threadPoolAllocator;
return *static_cast<TPoolAllocator*>(OS_GetTLSValue(PoolIndex));
}
// Set the thread-specific current pool.
void SetThreadPoolAllocator(TPoolAllocator* poolAllocator)
{
GetThreadMemoryPools()->threadPoolAllocator = poolAllocator;
OS_SetTLSValue(PoolIndex, poolAllocator);
}
// Process-wide set up of the TLS pool storage.
@ -81,39 +62,9 @@ bool InitializePoolIndex()
if ((PoolIndex = OS_AllocTLSIndex()) == OS_INVALID_TLS_INDEX)
return false;
SetThreadMemoryPools(nullptr);
return true;
}
// Process-wide tear down of the TLS pool storage.
void FreePoolIndex()
{
// Release the TLS index.
OS_FreeTLSIndex(PoolIndex);
}
// Per-thread set up of the memory pools.
void InitializeMemoryPools()
{
if (GetThreadMemoryPools() == nullptr) {
SetThreadMemoryPools(new TThreadMemoryPools());
GetThreadMemoryPools()->initialMemoryPool = new TPoolAllocator();
SetThreadPoolAllocator(GetThreadMemoryPools()->initialMemoryPool);
}
}
// Per-thread tear down of the memory pools.
void FreeMemoryPools()
{
if (GetThreadMemoryPools() != nullptr) {
if (GetThreadMemoryPools()->initialMemoryPool != nullptr)
delete GetThreadMemoryPools()->initialMemoryPool;
delete GetThreadMemoryPools();
SetThreadMemoryPools(nullptr);
}
}
//
// Implement the functionality of the TPoolAllocator class, which
// is documented in PoolAlloc.h.