Add JobSystem.Execute utility for quick jobs running

This commit is contained in:
Wojciech Figat
2022-02-14 14:34:43 +01:00
parent 9dc49f7165
commit 7979831f5c
2 changed files with 25 additions and 1 deletions

View File

@@ -212,6 +212,23 @@ int32 JobSystemThread::Run()
#endif
void JobSystem::Execute(const Function<void(int32)>& job, int32 jobCount)
{
// TODO: disable async if called on job thread? or maybe Wait should handle waiting in job thread to do the processing?
if (jobCount > 1)
{
// Async
const int64 jobWaitHandle = Dispatch(job, jobCount);
Wait(jobWaitHandle);
}
else if (jobCount > 0)
{
// Sync
for (int32 i = 0; i < jobCount; i++)
job(i);
}
}
int64 JobSystem::Dispatch(const Function<void(int32)>& job, int32 jobCount)
{
PROFILE_CPU();