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.
This commit is contained in:
parent
3971424207
commit
4302d51868
@ -1343,7 +1343,6 @@ int ShInitialize()
|
|||||||
|
|
||||||
glslang::GetGlobalLock();
|
glslang::GetGlobalLock();
|
||||||
++NumberOfClients;
|
++NumberOfClients;
|
||||||
glslang::ReleaseGlobalLock();
|
|
||||||
|
|
||||||
if (PerProcessGPA == nullptr)
|
if (PerProcessGPA == nullptr)
|
||||||
PerProcessGPA = new TPoolAllocator();
|
PerProcessGPA = new TPoolAllocator();
|
||||||
@ -1353,6 +1352,7 @@ int ShInitialize()
|
|||||||
glslang::HlslScanContext::fillInKeywordMap();
|
glslang::HlslScanContext::fillInKeywordMap();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
glslang::ReleaseGlobalLock();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1415,9 +1415,10 @@ int ShFinalize()
|
|||||||
--NumberOfClients;
|
--NumberOfClients;
|
||||||
assert(NumberOfClients >= 0);
|
assert(NumberOfClients >= 0);
|
||||||
bool finalize = NumberOfClients == 0;
|
bool finalize = NumberOfClients == 0;
|
||||||
glslang::ReleaseGlobalLock();
|
if (! finalize) {
|
||||||
if (! finalize)
|
glslang::ReleaseGlobalLock();
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
for (int version = 0; version < VersionCount; ++version) {
|
for (int version = 0; version < VersionCount; ++version) {
|
||||||
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
|
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
|
||||||
@ -1455,6 +1456,7 @@ int ShFinalize()
|
|||||||
glslang::HlslScanContext::deleteKeywordMap();
|
glslang::HlslScanContext::deleteKeywordMap();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
glslang::ReleaseGlobalLock();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user