| 578 | #endif |
| 579 | |
| 580 | static void ProcessFinishedJobs(HJobContext context, jc::RingBuffer<HJob>& items) |
| 581 | { |
| 582 | JobThreadContext* ctx = &context->m_ThreadContext; |
| 583 | |
| 584 | uint32_t size = items.Size(); |
| 585 | for(uint32_t i = 0; i < size; ++i) |
| 586 | { |
| 587 | HJob hjob = items[i]; |
| 588 | |
| 589 | JobItem item; |
| 590 | { |
| 591 | DM_MUTEX_OPTIONAL_SCOPED_LOCK(ctx->m_Mutex); |
| 592 | JobItem* _item = GetJobItem(ctx, hjob); |
| 593 | |
| 594 | if (!_item) |
| 595 | { |
| 596 | continue; |
| 597 | } |
| 598 | |
| 599 | item = *_item; |
| 600 | _item->m_Status = JOBSYSTEM_STATUS_CALLBACK; |
| 601 | } |
| 602 | |
| 603 | Job& job = item.m_Job; |
| 604 | if (job.m_Callback) |
| 605 | { |
| 606 | // Don't keep the lock here, as the jobs may use their own locks, and it may easily lead to a dead lock |
| 607 | // (this is generally on the main thread which is less problematic, but still) |
| 608 | job.m_Callback(context, hjob, item.m_Status, job.m_Context, job.m_Data, item.m_Result); |
| 609 | } |
| 610 | |
| 611 | DM_MUTEX_OPTIONAL_SCOPED_LOCK(context->m_ThreadContext.m_Mutex); |
| 612 | FreeJob(ctx, hjob); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | HJobContext JobSystemCreate(const JobSystemCreateParams* create_params) |
| 617 | { |
no test coverage detected