| 424 | } |
| 425 | |
| 426 | void VirtualMachineEngine::Schedule(const ScheduleCtx& schedule_ctx) { |
| 427 | // Release finished instructions and try to schedule out instructions in DAG onto ready list. |
| 428 | if (unlikely(mut_active_stream_list()->size())) { ReleaseFinishedInstructions(schedule_ctx); } |
| 429 | // Try run the first barrier instruction. |
| 430 | if (unlikely(mut_barrier_instruction_list()->size())) { TryRunBarrierInstruction(schedule_ctx); } |
| 431 | // Handle pending instructions, and try schedule them to ready list. |
| 432 | // Use thread_unsafe_size to avoid acquiring mutex lock. |
| 433 | // The inconsistency between pending_instruction_list.list_head_.list_head_.container_ and |
| 434 | // pending_instruction_list.list_head_.list_head_.size_ is not a fatal error because |
| 435 | // VirtualMachineEngine::Schedule is always in a busy loop. All instructions will get handled |
| 436 | // eventually. |
| 437 | // VirtualMachineEngine::Receive may be less effiencient if the thread safe version |
| 438 | // `pending_instruction_list().size()` used here, because VirtualMachineEngine::Schedule is more |
| 439 | // likely to get the mutex lock. |
| 440 | if (unlikely(local_pending_instruction_list().size())) { |
| 441 | HandleLocalPending(); |
| 442 | } else if (unlikely(pending_instruction_list().thread_unsafe_size())) { |
| 443 | // MoveTo is under a lock. |
| 444 | mut_pending_instruction_list()->MoveTo(mut_local_pending_instruction_list()); |
| 445 | if (local_pending_instruction_list().size()) { HandleLocalPending(); } |
| 446 | } |
| 447 | // dispatch ready instructions and try to schedule out instructions in DAG onto ready list. |
| 448 | if (unlikely(mut_ready_instruction_list()->size())) { |
| 449 | DispatchAndPrescheduleInstructions(schedule_ctx); |
| 450 | } |
| 451 | // handle scheduler probes |
| 452 | if (unlikely(local_probe_list_.size())) { |
| 453 | HandleLocalProbe(); |
| 454 | } else if (unlikely(probe_list_.thread_unsafe_size())) { |
| 455 | probe_list_.MoveTo(&local_probe_list_); |
| 456 | if (local_probe_list_.size()) { HandleLocalProbe(); } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | bool VirtualMachineEngine::SchedulerThreadUnsafeEmpty() const { |
| 461 | return pending_instruction_list().thread_unsafe_size() == 0 |
no test coverage detected