MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Dispatch

Method Dispatch

Source/Engine/Threading/JobSystem.cpp:285–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283}
284
285int64 JobSystem::Dispatch(const Function<void(int32)>& job, int32 jobCount)
286{
287 if (jobCount <= 0)
288 return 0;
289 PROFILE_CPU();
290#if JOB_SYSTEM_ENABLED
291 while (Platform::InterlockedIncrement(&JobContextsCount) >= JobContextsSize)
292 {
293 // Too many jobs in flight, wait for some to complete to free up contexts
294 PROFILE_CPU_NAMED("JOB SYSTEM OVERFLOW");
295 ZoneColor(TracyWaitZoneColor);
296 Platform::InterlockedDecrement(&JobContextsCount);
297 Platform::Sleep(1);
298 }
299
300 // Get a new label
301 const int64 label = Platform::InterlockedIncrement(&JobLabel);
302
303 // Build job
304 JobContext& context = JobContexts[GET_CONTEXT_INDEX(label)];
305 context.Job = job;
306 context.JobIndex = 0;
307 context.JobsLeft = jobCount;
308 context.JobLabel = label;
309 context.DependantsCount = 0;
310 context.DependenciesLeft = 0;
311 context.JobsCount = jobCount;
312 context.Dependants.Clear();
313
314 // Move the job queue forward
315 Platform::InterlockedIncrement(&JobEndLabel);
316
317 if (JobStartingOnDispatch)
318 {
319 if (jobCount == 1)
320 JobsSignal.NotifyOne();
321 else
322 JobsSignal.NotifyAll();
323 }
324
325 return label;
326#else
327 for (int32 i = 0; i < jobCount; i++)
328 job(i);
329 return 0;
330#endif
331}
332
333int64 JobSystem::Dispatch(const Function<void(int32)>& job, Span<int64> dependencies, int32 jobCount)
334{

Callers 13

RenderMethod · 0.45
RenderMethod · 0.45
RenderMethod · 0.45
RenderMethod · 0.45
SortMethod · 0.45
RenderInnerMethod · 0.45
RenderMethod · 0.45
DrawEmittersGPUFunction · 0.45
SimMethod · 0.45
RunMethod · 0.45
CallSceneEventMethod · 0.45
callActorEventMethod · 0.45

Calls 7

LockMethod · 0.80
UnlockMethod · 0.80
InterlockedIncrementFunction · 0.50
InterlockedDecrementFunction · 0.50
AtomicReadFunction · 0.50
ClearMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected