diff --git a/Source/Engine/Content/Loading/ContentLoadingManager.cpp b/Source/Engine/Content/Loading/ContentLoadingManager.cpp index 14f57abf0..beccf511b 100644 --- a/Source/Engine/Content/Loading/ContentLoadingManager.cpp +++ b/Source/Engine/Content/Loading/ContentLoadingManager.cpp @@ -23,6 +23,7 @@ namespace ContentLoadingManagerImpl Array Threads; ConcurrentTaskQueue Tasks; ConditionVariable TasksSignal; + CriticalSection TasksMutex; }; using namespace ContentLoadingManagerImpl; @@ -121,7 +122,6 @@ int32 LoadingThread::Run() #endif ContentLoadTask* task; - CriticalSection mutex; ThisThread = this; while (HasExitFlagClear()) @@ -132,9 +132,9 @@ int32 LoadingThread::Run() } else { - mutex.Lock(); - TasksSignal.Wait(mutex); - mutex.Unlock(); + TasksMutex.Lock(); + TasksSignal.Wait(TasksMutex); + TasksMutex.Unlock(); } } diff --git a/Source/Engine/Threading/JobSystem.cpp b/Source/Engine/Threading/JobSystem.cpp index 3f4e7e297..6ef56e6ef 100644 --- a/Source/Engine/Threading/JobSystem.cpp +++ b/Source/Engine/Threading/JobSystem.cpp @@ -92,7 +92,9 @@ namespace volatile int64 DoneLabel = 0; volatile int64 NextLabel = 0; ConditionVariable JobsSignal; + CriticalSection JobsMutex; ConditionVariable WaitSignal; + CriticalSection WaitMutex; #if JOB_SYSTEM_USE_MUTEX CriticalSection JobsLocker; RingBuffer> Jobs; @@ -149,7 +151,6 @@ int32 JobSystemThread::Run() Platform::SetThreadAffinityMask(1ull << Index); JobData data; - CriticalSection mutex; bool attachMonoThread = true; #if !JOB_SYSTEM_USE_MUTEX moodycamel::ConsumerToken consumerToken(Jobs); @@ -201,9 +202,9 @@ int32 JobSystemThread::Run() else { // Wait for signal - mutex.Lock(); - JobsSignal.Wait(mutex); - mutex.Unlock(); + JobsMutex.Lock(); + JobsSignal.Wait(JobsMutex); + JobsMutex.Unlock(); } } return 0; @@ -272,12 +273,11 @@ void JobSystem::Wait(int64 label) return; // Wait on signal until input label is not yet done - CriticalSection mutex; do { - mutex.Lock(); - WaitSignal.Wait(mutex, 1); - mutex.Unlock(); + WaitMutex.Lock(); + WaitSignal.Wait(WaitMutex, 1); + WaitMutex.Unlock(); } while (label > Platform::AtomicRead(&DoneLabel) && Platform::AtomicRead(&ExitFlag) == 0); #if JOB_SYSTEM_USE_STATS diff --git a/Source/Engine/Threading/ThreadPool.cpp b/Source/Engine/Threading/ThreadPool.cpp index a9926f47e..2927238ed 100644 --- a/Source/Engine/Threading/ThreadPool.cpp +++ b/Source/Engine/Threading/ThreadPool.cpp @@ -24,6 +24,7 @@ namespace ThreadPoolImpl Array Threads; ConcurrentTaskQueue Jobs; // Hello Steve! ConditionVariable JobsSignal; + CriticalSection JobsMutex; } void ThreadPoolTask::Enqueue() @@ -104,7 +105,6 @@ int32 ThreadPool::ThreadProc() ThreadPoolTask* task; // Work until end - CriticalSection mutex; while (Platform::AtomicRead(&ThreadPoolImpl::ExitFlag) == 0) { // Try to get a job @@ -114,9 +114,9 @@ int32 ThreadPool::ThreadProc() } else { - mutex.Lock(); - ThreadPoolImpl::JobsSignal.Wait(mutex); - mutex.Unlock(); + ThreadPoolImpl::JobsMutex.Lock(); + ThreadPoolImpl::JobsSignal.Wait(ThreadPoolImpl::JobsMutex); + ThreadPoolImpl::JobsMutex.Unlock(); } }