Commit 4ceaab16 by John Kessenich

Memory: Move to a normal model of ownership of memory pools, for new/delete.

Addresses step 4 of #976, overlaps #916. For each pool, now, it is newed, remembered, and freed by the same entity, rather than having a mix (thread finalize freeing current pool) that could lead to double freeing of the same pool. It is quite rational and simple now. This will enable reinstalling process and thread tear down.
parent be209055
...@@ -47,6 +47,7 @@ OS_TLSIndex PoolIndex; ...@@ -47,6 +47,7 @@ OS_TLSIndex PoolIndex;
struct TThreadMemoryPools struct TThreadMemoryPools
{ {
TPoolAllocator* threadPoolAllocator; // the current pool 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. // Return the thread-specific pool pointers.
...@@ -80,6 +81,8 @@ bool InitializePoolIndex() ...@@ -80,6 +81,8 @@ bool InitializePoolIndex()
if ((PoolIndex = OS_AllocTLSIndex()) == OS_INVALID_TLS_INDEX) if ((PoolIndex = OS_AllocTLSIndex()) == OS_INVALID_TLS_INDEX)
return false; return false;
SetThreadMemoryPools(nullptr);
return true; return true;
} }
...@@ -95,7 +98,8 @@ void InitializeMemoryPools() ...@@ -95,7 +98,8 @@ void InitializeMemoryPools()
{ {
if (GetThreadMemoryPools() == nullptr) { if (GetThreadMemoryPools() == nullptr) {
SetThreadMemoryPools(new TThreadMemoryPools()); SetThreadMemoryPools(new TThreadMemoryPools());
SetThreadPoolAllocator(new TPoolAllocator()); GetThreadMemoryPools()->initialMemoryPool = new TPoolAllocator();
SetThreadPoolAllocator(GetThreadMemoryPools()->initialMemoryPool);
} }
} }
...@@ -103,9 +107,10 @@ void InitializeMemoryPools() ...@@ -103,9 +107,10 @@ void InitializeMemoryPools()
void FreeMemoryPools() void FreeMemoryPools()
{ {
if (GetThreadMemoryPools() != nullptr) { if (GetThreadMemoryPools() != nullptr) {
GetThreadPoolAllocator().popAll(); if (GetThreadMemoryPools()->initialMemoryPool != nullptr)
delete &GetThreadPoolAllocator(); delete GetThreadMemoryPools()->initialMemoryPool;
delete GetThreadMemoryPools(); delete GetThreadMemoryPools();
SetThreadMemoryPools(nullptr);
} }
} }
......
...@@ -1602,8 +1602,9 @@ public: ...@@ -1602,8 +1602,9 @@ public:
}; };
TShader::TShader(EShLanguage s) TShader::TShader(EShLanguage s)
: pool(0), stage(s), lengths(nullptr), stringNames(nullptr), preamble("") : stage(s), lengths(nullptr), stringNames(nullptr), preamble("")
{ {
pool = new TPoolAllocator;
infoSink = new TInfoSink; infoSink = new TInfoSink;
compiler = new TDeferredCompiler(stage, *infoSink); compiler = new TDeferredCompiler(stage, *infoSink);
intermediate = new TIntermediate(s); intermediate = new TIntermediate(s);
...@@ -1707,7 +1708,6 @@ bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion ...@@ -1707,7 +1708,6 @@ bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion
if (! InitThread()) if (! InitThread())
return false; return false;
pool = new TPoolAllocator();
SetThreadPoolAllocator(pool); SetThreadPoolAllocator(pool);
if (! preamble) if (! preamble)
preamble = ""; preamble = "";
...@@ -1731,7 +1731,6 @@ bool TShader::preprocess(const TBuiltInResource* builtInResources, ...@@ -1731,7 +1731,6 @@ bool TShader::preprocess(const TBuiltInResource* builtInResources,
if (! InitThread()) if (! InitThread())
return false; return false;
pool = new TPoolAllocator();
SetThreadPoolAllocator(pool); SetThreadPoolAllocator(pool);
if (! preamble) if (! preamble)
preamble = ""; preamble = "";
...@@ -1752,8 +1751,9 @@ const char* TShader::getInfoDebugLog() ...@@ -1752,8 +1751,9 @@ const char* TShader::getInfoDebugLog()
return infoSink->debug.c_str(); return infoSink->debug.c_str();
} }
TProgram::TProgram() : pool(0), reflection(0), ioMapper(nullptr), linked(false) TProgram::TProgram() : reflection(0), ioMapper(nullptr), linked(false)
{ {
pool = new TPoolAllocator;
infoSink = new TInfoSink; infoSink = new TInfoSink;
for (int s = 0; s < EShLangCount; ++s) { for (int s = 0; s < EShLangCount; ++s) {
intermediate[s] = 0; intermediate[s] = 0;
...@@ -1788,7 +1788,6 @@ bool TProgram::link(EShMessages messages) ...@@ -1788,7 +1788,6 @@ bool TProgram::link(EShMessages messages)
bool error = false; bool error = false;
pool = new TPoolAllocator();
SetThreadPoolAllocator(pool); SetThreadPoolAllocator(pool);
for (int s = 0; s < EShLangCount; ++s) { for (int s = 0; s < EShLangCount; ++s) {
......
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