Optimize wait signal in Job System to wake waiting threads only when job batch ends

This commit is contained in:
Wojtek Figat
2024-06-22 09:58:20 +02:00
parent 3b3cd5ade4
commit 2773949197

View File

@@ -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();
}