diff --git a/glslang/MachineIndependent/PoolAlloc.cpp b/glslang/MachineIndependent/PoolAlloc.cpp index 5d7173c9..93a3b0d1 100644 --- a/glslang/MachineIndependent/PoolAlloc.cpp +++ b/glslang/MachineIndependent/PoolAlloc.cpp @@ -35,14 +35,21 @@ #include "../Include/Common.h" #include "../Include/PoolAlloc.h" +// Mostly here for target that do not support threads such as WASI. +#ifdef DISABLE_THREAD_SUPPORT +#define THREAD_LOCAL +#else +#define THREAD_LOCAL thread_local +#endif + namespace glslang { namespace { -thread_local TPoolAllocator* threadPoolAllocator = nullptr; +THREAD_LOCAL TPoolAllocator* threadPoolAllocator = nullptr; TPoolAllocator* GetDefaultThreadPoolAllocator() { - thread_local TPoolAllocator defaultAllocator; + THREAD_LOCAL TPoolAllocator defaultAllocator; return &defaultAllocator; } } // anonymous namespace diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index 034a0306..be3248e3 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -82,7 +82,10 @@ namespace { // anonymous namespace for file-local functions and symbols int NumberOfClients = 0; // global initialization lock +#ifndef DISABLE_THREAD_SUPPORT std::mutex init_lock; +#endif + using namespace glslang; @@ -420,7 +423,9 @@ void SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp TInfoSink infoSink; // Make sure only one thread tries to do this at a time +#ifndef DISABLE_THREAD_SUPPORT const std::lock_guard lock(init_lock); +#endif // See if it's already been done for this version/profile combination int versionIndex = MapVersionToIndex(version); @@ -1311,7 +1316,9 @@ bool CompileDeferred( // int ShInitialize() { +#ifndef DISABLE_THREAD_SUPPORT const std::lock_guard lock(init_lock); +#endif ++NumberOfClients; if (PerProcessGPA == nullptr) @@ -1371,7 +1378,9 @@ void ShDestruct(ShHandle handle) // int ShFinalize() { +#ifndef DISABLE_THREAD_SUPPORT const std::lock_guard lock(init_lock); +#endif --NumberOfClients; assert(NumberOfClients >= 0); if (NumberOfClients > 0)