Adding the preprocessor value DISABLE_THREAD_SUPPORT to allow compilation of glslang without thread support for WASI.

This commit is contained in:
Antoine 2024-05-22 22:56:43 +02:00 committed by arcady-lunarg
parent ea087ff90d
commit 20490a11aa
2 changed files with 18 additions and 2 deletions

View file

@ -35,14 +35,21 @@
#include "../Include/Common.h" #include "../Include/Common.h"
#include "../Include/PoolAlloc.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 glslang {
namespace { namespace {
thread_local TPoolAllocator* threadPoolAllocator = nullptr; THREAD_LOCAL TPoolAllocator* threadPoolAllocator = nullptr;
TPoolAllocator* GetDefaultThreadPoolAllocator() TPoolAllocator* GetDefaultThreadPoolAllocator()
{ {
thread_local TPoolAllocator defaultAllocator; THREAD_LOCAL TPoolAllocator defaultAllocator;
return &defaultAllocator; return &defaultAllocator;
} }
} // anonymous namespace } // anonymous namespace

View file

@ -82,7 +82,10 @@ namespace { // anonymous namespace for file-local functions and symbols
int NumberOfClients = 0; int NumberOfClients = 0;
// global initialization lock // global initialization lock
#ifndef DISABLE_THREAD_SUPPORT
std::mutex init_lock; std::mutex init_lock;
#endif
using namespace glslang; using namespace glslang;
@ -420,7 +423,9 @@ void SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp
TInfoSink infoSink; TInfoSink infoSink;
// Make sure only one thread tries to do this at a time // 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 // See if it's already been done for this version/profile combination
int versionIndex = MapVersionToIndex(version); int versionIndex = MapVersionToIndex(version);
@ -1311,7 +1316,9 @@ bool CompileDeferred(
// //
int ShInitialize() 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; ++NumberOfClients;
if (PerProcessGPA == nullptr) if (PerProcessGPA == nullptr)
@ -1371,7 +1378,9 @@ void ShDestruct(ShHandle handle)
// //
int ShFinalize() 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; --NumberOfClients;
assert(NumberOfClients >= 0); assert(NumberOfClients >= 0);
if (NumberOfClients > 0) if (NumberOfClients > 0)