From 87a83d684142b14086be25c074eaf7395645ca21 Mon Sep 17 00:00:00 2001 From: Josh Gargus Date: Wed, 5 Oct 2016 18:32:51 -0700 Subject: [PATCH 1/2] Use pthread_mutex for global lock on Linux. --- glslang/OSDependent/Unix/ossource.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/glslang/OSDependent/Unix/ossource.cpp b/glslang/OSDependent/Unix/ossource.cpp index 8e583ea7..0e6d7307 100644 --- a/glslang/OSDependent/Unix/ossource.cpp +++ b/glslang/OSDependent/Unix/ossource.cpp @@ -165,11 +165,12 @@ bool OS_FreeTLSIndex(OS_TLSIndex nIndex) return false; } -// TODO: non-windows: if we need these on linux, flesh them out -void InitGlobalLock() { } -void GetGlobalLock() { } -void ReleaseGlobalLock() { } +static pthread_mutex_t gMutex; +void InitGlobalLock() { pthread_mutex_init(&gMutex, NULL); } +void GetGlobalLock() { pthread_mutex_lock(&gMutex); } +void ReleaseGlobalLock() { pthread_mutex_unlock(&gMutex); } +// TODO: non-windows: if we need these on linux, flesh them out void* OS_CreateThread(TThreadEntrypoint /*entry*/) { return 0; From 425af5f6b03b66ff14283d4ba9e8c045d453514f Mon Sep 17 00:00:00 2001 From: Josh Gargus Date: Sat, 15 Oct 2016 15:19:59 -0700 Subject: [PATCH 2/2] Use a recursive mutex. --- glslang/OSDependent/Unix/ossource.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/glslang/OSDependent/Unix/ossource.cpp b/glslang/OSDependent/Unix/ossource.cpp index 0e6d7307..7e84d4eb 100644 --- a/glslang/OSDependent/Unix/ossource.cpp +++ b/glslang/OSDependent/Unix/ossource.cpp @@ -165,10 +165,27 @@ bool OS_FreeTLSIndex(OS_TLSIndex nIndex) return false; } -static pthread_mutex_t gMutex; -void InitGlobalLock() { pthread_mutex_init(&gMutex, NULL); } -void GetGlobalLock() { pthread_mutex_lock(&gMutex); } -void ReleaseGlobalLock() { pthread_mutex_unlock(&gMutex); } +namespace { +pthread_mutex_t gMutex; +} + +void InitGlobalLock() +{ + pthread_mutexattr_t mutexattr; + pthread_mutexattr_init(&mutexattr); + pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&gMutex, &mutexattr); +} + +void GetGlobalLock() +{ + pthread_mutex_lock(&gMutex); +} + +void ReleaseGlobalLock() +{ + pthread_mutex_unlock(&gMutex); +} // TODO: non-windows: if we need these on linux, flesh them out void* OS_CreateThread(TThreadEntrypoint /*entry*/)