| 283 | } |
| 284 | |
| 285 | int64 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 | |
| 333 | int64 JobSystem::Dispatch(const Function<void(int32)>& job, Span<int64> dependencies, int32 jobCount) |
| 334 | { |
no test coverage detected