diff options
author | Niklas Haas <git@haasn.dev> | 2021-11-08 14:58:50 +0100 |
---|---|---|
committer | Niklas Haas <git@haasn.dev> | 2021-11-08 15:00:28 +0100 |
commit | 4302d51868daa94e81d3002073e9265397b2e444 (patch) | |
tree | 1a5eef53e6e2c82465918873fb924b8d6e455b6e | |
parent | 3971424207e27a662d4416eedfb68e18ff287350 (diff) | |
download | glslang-4302d51868daa94e81d3002073e9265397b2e444.tar.gz |
Don't release global mutex before initialize/finalize is done
Otherwise this can race with other threads for access to the fields it's
supposed to be initializing/finalizing.
For example, imagine another thread is calling ShInitialize() while the
first thread is calling ShFinalize() - the finalize function would
destroy the state at the same time as the initialize function is trying
to initialize it.
Holding on to the global lock for the entire function prevents all of
these failure modes.
-rw-r--r-- | glslang/MachineIndependent/ShaderLang.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index d02eae6f..a2dd71cf 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -1343,7 +1343,6 @@ int ShInitialize() glslang::GetGlobalLock(); ++NumberOfClients; - glslang::ReleaseGlobalLock(); if (PerProcessGPA == nullptr) PerProcessGPA = new TPoolAllocator(); @@ -1353,6 +1352,7 @@ int ShInitialize() glslang::HlslScanContext::fillInKeywordMap(); #endif + glslang::ReleaseGlobalLock(); return 1; } @@ -1415,9 +1415,10 @@ int ShFinalize() --NumberOfClients; assert(NumberOfClients >= 0); bool finalize = NumberOfClients == 0; - glslang::ReleaseGlobalLock(); - if (! finalize) + if (! finalize) { + glslang::ReleaseGlobalLock(); return 1; + } for (int version = 0; version < VersionCount; ++version) { for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) { @@ -1455,6 +1456,7 @@ int ShFinalize() glslang::HlslScanContext::deleteKeywordMap(); #endif + glslang::ReleaseGlobalLock(); return 1; } |