MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ drain_pending_tasks()

void MayaFlux::Vruta::TaskScheduler::drain_pending_tasks ( )
private

Drain pending task operations (additions/removals) before processing.

This method ensures that any tasks that were added or removed while processing are properly handled before the next processing cycle.

Definition at line 705 of file Scheduler.cpp.

706{
707 if (m_pending_count.load(std::memory_order_relaxed) == 0)
708 return;
709
710 DrainScope drain_scope(this);
711
712 for (auto& op : m_pending_ops) {
713 if (!op.active.load(std::memory_order_acquire))
714 continue;
715
716 if (op.is_addition) {
717 auto existing_it = find_task_by_name(op.entry.name);
718 if (existing_it != m_tasks.end()) {
719 if (existing_it->routine && existing_it->routine->is_active())
720 existing_it->routine->set_should_terminate(true);
721 m_tasks.erase(existing_it);
722 }
723 m_tasks.push_back(std::move(op.entry));
724 } else {
725 auto it = (op.entry.name.empty() && op.entry.routine)
726 ? find_task_by_routine(op.entry.routine)
727 : find_task_by_name(op.entry.name);
728 if (it != m_tasks.end()) {
729 if (it->routine && it->routine->is_active())
730 it->routine->set_should_terminate(true);
731 m_tasks.erase(it);
732 }
733 }
734
735 op.entry = { nullptr, "" };
736 op.active.store(false, std::memory_order_release);
737 m_pending_count.fetch_sub(1, std::memory_order_relaxed);
738 }
739}
std::atomic< uint32_t > m_pending_count
std::vector< TaskEntry > m_tasks
PendingTaskOp m_pending_ops[MAX_PENDING_TASKS]
std::vector< TaskEntry >::iterator find_task_by_name(const std::string &name)
Find task entry by name.
std::vector< TaskEntry >::iterator find_task_by_routine(const std::shared_ptr< Routine > &routine)
Find task entry by routine pointer.

References find_task_by_name(), find_task_by_routine(), m_pending_count, m_pending_ops, and m_tasks.

Referenced by get_all_tasks(), process_buffer_cycle_tasks(), process_token(), and terminate_all_tasks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: