mirror of
https://github.com/RPCS3/glslang.git
synced 2024-11-23 11:19:40 +00:00
Replace GlobalLock functions with std::mutex
The usage of GetGlobalLock/ReleaseGlobalLock/InitGlobalLock is replaced by std::lock_guard which is available as of c++11, and the functions are removed from the OSDependent ossource.cpp files. The standalone glslang binary now explicitly depends on OSDependent, as nothing in in the glslang library uses those functions anymore and they are not implicitly picked up by the linker.
This commit is contained in:
parent
1b37f3a490
commit
b4443eb859
@ -54,6 +54,7 @@ glslang_set_link_args(glslang-standalone)
|
||||
|
||||
set(LIBRARIES
|
||||
glslang
|
||||
OSDependent
|
||||
SPIRV
|
||||
glslang-default-resource-limits)
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include "SymbolTable.h"
|
||||
#include "ParseHelper.h"
|
||||
#include "Scan.h"
|
||||
@ -81,6 +82,9 @@ namespace { // anonymous namespace for file-local functions and symbols
|
||||
// Shared global; access should be protected by a global mutex/critical section.
|
||||
int NumberOfClients = 0;
|
||||
|
||||
// global initialization lock
|
||||
std::mutex init_lock;
|
||||
|
||||
using namespace glslang;
|
||||
|
||||
// Create a language specific version of parseables.
|
||||
@ -417,18 +421,15 @@ void SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp
|
||||
TInfoSink infoSink;
|
||||
|
||||
// Make sure only one thread tries to do this at a time
|
||||
glslang::GetGlobalLock();
|
||||
const std::lock_guard<std::mutex> lock(init_lock);
|
||||
|
||||
// See if it's already been done for this version/profile combination
|
||||
int versionIndex = MapVersionToIndex(version);
|
||||
int spvVersionIndex = MapSpvVersionToIndex(spvVersion);
|
||||
int profileIndex = MapProfileToIndex(profile);
|
||||
int sourceIndex = MapSourceToIndex(source);
|
||||
if (CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][EPcGeneral]) {
|
||||
glslang::ReleaseGlobalLock();
|
||||
|
||||
if (CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][EPcGeneral])
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch to a new pool
|
||||
TPoolAllocator& previousAllocator = GetThreadPoolAllocator();
|
||||
@ -475,8 +476,6 @@ void SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp
|
||||
|
||||
delete builtInPoolAllocator;
|
||||
SetThreadPoolAllocator(&previousAllocator);
|
||||
|
||||
glslang::ReleaseGlobalLock();
|
||||
}
|
||||
|
||||
// Function to Print all builtins
|
||||
@ -1297,12 +1296,10 @@ bool CompileDeferred(
|
||||
//
|
||||
int ShInitialize()
|
||||
{
|
||||
glslang::InitGlobalLock();
|
||||
|
||||
if (! InitProcess())
|
||||
return 0;
|
||||
|
||||
glslang::GetGlobalLock();
|
||||
const std::lock_guard<std::mutex> lock(init_lock);
|
||||
++NumberOfClients;
|
||||
|
||||
if (PerProcessGPA == nullptr)
|
||||
@ -1313,7 +1310,6 @@ int ShInitialize()
|
||||
glslang::HlslScanContext::fillInKeywordMap();
|
||||
#endif
|
||||
|
||||
glslang::ReleaseGlobalLock();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1372,14 +1368,11 @@ void ShDestruct(ShHandle handle)
|
||||
//
|
||||
int ShFinalize()
|
||||
{
|
||||
glslang::GetGlobalLock();
|
||||
const std::lock_guard<std::mutex> lock(init_lock);
|
||||
--NumberOfClients;
|
||||
assert(NumberOfClients >= 0);
|
||||
bool finalize = NumberOfClients == 0;
|
||||
if (! finalize) {
|
||||
glslang::ReleaseGlobalLock();
|
||||
if (NumberOfClients > 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int version = 0; version < VersionCount; ++version) {
|
||||
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
|
||||
@ -1417,7 +1410,6 @@ int ShFinalize()
|
||||
glslang::HlslScanContext::deleteKeywordMap();
|
||||
#endif
|
||||
|
||||
glslang::ReleaseGlobalLock();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -36,15 +36,8 @@
|
||||
// This file contains the Linux-specific functions
|
||||
//
|
||||
#include "../osinclude.h"
|
||||
#include "../../../OGLCompilersDLL/InitializeDll.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <cstdio>
|
||||
#include <sys/time.h>
|
||||
|
||||
#if !defined(__Fuchsia__)
|
||||
#include <sys/resource.h>
|
||||
@ -52,34 +45,6 @@
|
||||
|
||||
namespace glslang {
|
||||
|
||||
namespace {
|
||||
pthread_mutex_t gMutex;
|
||||
}
|
||||
|
||||
static void InitMutex(void)
|
||||
{
|
||||
pthread_mutexattr_t mutexattr;
|
||||
pthread_mutexattr_init(&mutexattr);
|
||||
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&gMutex, &mutexattr);
|
||||
}
|
||||
|
||||
void InitGlobalLock()
|
||||
{
|
||||
static pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
pthread_once(&once, InitMutex);
|
||||
}
|
||||
|
||||
void GetGlobalLock()
|
||||
{
|
||||
pthread_mutex_lock(&gMutex);
|
||||
}
|
||||
|
||||
void ReleaseGlobalLock()
|
||||
{
|
||||
pthread_mutex_unlock(&gMutex);
|
||||
}
|
||||
|
||||
// #define DUMP_COUNTERS
|
||||
|
||||
void OS_DumpMemoryCounters()
|
||||
|
@ -37,11 +37,9 @@
|
||||
#define STRICT
|
||||
#define VC_EXTRALEAN 1
|
||||
#include <windows.h>
|
||||
#include <cassert>
|
||||
#include <process.h>
|
||||
#include <psapi.h>
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
//
|
||||
// This file contains the Window-OS-specific functions
|
||||
@ -53,28 +51,6 @@
|
||||
|
||||
namespace glslang {
|
||||
|
||||
HANDLE GlobalLock;
|
||||
|
||||
void InitGlobalLock()
|
||||
{
|
||||
GlobalLock = CreateMutex(nullptr, false, nullptr);
|
||||
}
|
||||
|
||||
void GetGlobalLock()
|
||||
{
|
||||
WaitForSingleObject(GlobalLock, INFINITE);
|
||||
}
|
||||
|
||||
void ReleaseGlobalLock()
|
||||
{
|
||||
ReleaseMutex(GlobalLock);
|
||||
}
|
||||
|
||||
unsigned int __stdcall EnterGenericThread (void* entry)
|
||||
{
|
||||
return ((TThreadEntrypoint)entry)(nullptr);
|
||||
}
|
||||
|
||||
//#define DUMP_COUNTERS
|
||||
|
||||
void OS_DumpMemoryCounters()
|
||||
|
@ -37,12 +37,6 @@
|
||||
|
||||
namespace glslang {
|
||||
|
||||
void InitGlobalLock();
|
||||
void GetGlobalLock();
|
||||
void ReleaseGlobalLock();
|
||||
|
||||
typedef unsigned int (*TThreadEntrypoint)(void*);
|
||||
|
||||
void OS_DumpMemoryCounters();
|
||||
|
||||
} // end namespace glslang
|
||||
|
Loading…
Reference in New Issue
Block a user