mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-10 12:30:05 +00:00
Initialize global mutex in a thread-safe manner
Currently, ShInitialize() and friends call glslang::InitGlobalLock() which *overwrites* the global mutex. As such, even though it ostensibly takes a mutex, this function is actually completely thread-unsafe. Fix it by using pthread_once to ensure the mutex is only initialized once, and then never again.
This commit is contained in:
parent
eb92526d5e
commit
3971424207
@ -172,7 +172,7 @@ namespace {
|
||||
pthread_mutex_t gMutex;
|
||||
}
|
||||
|
||||
void InitGlobalLock()
|
||||
static void InitMutex(void)
|
||||
{
|
||||
pthread_mutexattr_t mutexattr;
|
||||
pthread_mutexattr_init(&mutexattr);
|
||||
@ -180,6 +180,12 @@ void InitGlobalLock()
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user