Allow glslang global lock to be used during process teardown

* During capture we may have to shutdown glslang from inside a global
  destructor, we need to ensure the lock is still valid.
This commit is contained in:
baldurk
2025-03-05 09:50:29 +00:00
parent c6cf956d50
commit b813fb2436
@@ -83,7 +83,11 @@ int NumberOfClients = 0;
// global initialization lock
#ifndef DISABLE_THREAD_SUPPORT
std::mutex init_lock;
std::mutex &init_lock()
{
std::mutex *lock = new std::mutex;
return *lock;
}
#endif
@@ -430,7 +434,7 @@ bool SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp
// Make sure only one thread tries to do this at a time
#ifndef DISABLE_THREAD_SUPPORT
const std::lock_guard<std::mutex> lock(init_lock);
const std::lock_guard<std::mutex> lock(init_lock());
#endif
// See if it's already been done for this version/profile combination
@@ -1333,7 +1337,7 @@ bool CompileDeferred(
int ShInitialize()
{
#ifndef DISABLE_THREAD_SUPPORT
const std::lock_guard<std::mutex> lock(init_lock);
const std::lock_guard<std::mutex> lock(init_lock());
#endif
++NumberOfClients;
@@ -1390,7 +1394,7 @@ void ShDestruct(ShHandle handle)
int ShFinalize()
{
#ifndef DISABLE_THREAD_SUPPORT
const std::lock_guard<std::mutex> lock(init_lock);
const std::lock_guard<std::mutex> lock(init_lock());
#endif
--NumberOfClients;
assert(NumberOfClients >= 0);