From 27739491977c643916f4ca30f71043d74b448f90 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sat, 22 Jun 2024 09:58:20 +0200 Subject: [PATCH] Optimize wait signal in Job System to wake waiting threads only when job batch ends --- Source/Engine/Threading/JobSystem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Threading/JobSystem.cpp b/Source/Engine/Threading/JobSystem.cpp index f278d7d02..090bab2ea 100644 --- a/Source/Engine/Threading/JobSystem.cpp +++ b/Source/Engine/Threading/JobSystem.cpp @@ -200,16 +200,19 @@ int32 JobSystemThread::Run() data.Job(data.Index); // Move forward with the job queue + bool notifyWaiting = false; JobsLocker.Lock(); JobContext& context = JobContexts.At(data.JobKey); if (Platform::InterlockedDecrement(&context.JobsLeft) <= 0) { ASSERT_LOW_LAYER(context.JobsLeft <= 0); JobContexts.Remove(data.JobKey); + notifyWaiting = true; } JobsLocker.Unlock(); - WaitSignal.NotifyAll(); + if (notifyWaiting) + WaitSignal.NotifyAll(); data.Job.Unbind(); }