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

@@ -38,8 +38,8 @@
#include "InitializeDll.h"
#include "../glslang/Include/InitializeGlobals.h"
#include "../glslang/Public/ShaderLang.h"
#include "../glslang/Include/PoolAlloc.h"
namespace glslang {
@@ -105,57 +105,14 @@ bool InitThread()
if (OS_GetTLSValue(ThreadInitializeIndex) != 0)
return true;
InitializeMemoryPools();
if (! OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
assert(0 && "InitThread(): Unable to set init flag.");
return false;
}
glslang::SetThreadPoolAllocator(nullptr);
return true;
}
// Thread-scoped tear down. Needs to be done by all but the last
// thread, which calls DetachProcess() instead.
// NB. TODO: Not currently being executed by each thread.
bool DetachThread()
{
bool success = true;
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
return true;
//
// Function is re-entrant and this thread may not have been initialized.
//
if (OS_GetTLSValue(ThreadInitializeIndex) != 0) {
if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)0)) {
assert(0 && "DetachThread(): Unable to clear init flag.");
success = false;
}
FreeMemoryPools();
}
return success;
}
// Process-scoped tear down. Needs to be done by final thread in process.
bool DetachProcess()
{
bool success = true;
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
return true;
success = DetachThread();
FreePoolIndex();
OS_FreeTLSIndex(ThreadInitializeIndex);
ThreadInitializeIndex = OS_INVALID_TLS_INDEX;
return success;
}
} // end namespace glslang

View File

@@ -40,8 +40,6 @@ namespace glslang {
bool InitProcess();
bool InitThread();
bool DetachThread(); // TODO: use this or remove it; ideally make it unneeded
bool DetachProcess();
} // end namespace glslang