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

◆ cancel_task() [1/2]

bool MayaFlux::Vruta::TaskScheduler::cancel_task ( const std::shared_ptr< Routine > &  routine)

Cancels and removes a task from the scheduler.

Parameters
routineShared pointer to the task to cancel
Returns
True if the task was found and cancelled, false otherwise

This method removes a task from the scheduler, preventing it from executing further. It's used to stop tasks that are no longer needed or to clean up before shutting down the engine.

Definition at line 101 of file Scheduler.cpp.

102{
103 if (!routine)
104 return false;
105
106 if (routine && routine->get_processing_token() == ProcessingToken::CONDITIONAL) {
107 auto it = std::ranges::find_if(m_conditional_tasks,
108 [&routine](const TaskEntry& e) { return e.routine == routine; });
109 const std::string name = (it != m_conditional_tasks.end()) ? it->name : "";
110 return cancel_task(name);
111 }
112
113 auto it = find_task_by_routine(routine);
114 const std::string name = (it != m_tasks.end()) ? it->name : "";
115
116 for (auto& op : m_pending_ops) {
117 bool expected = false;
118 if (op.active.compare_exchange_strong(expected, true,
119 std::memory_order_acquire, std::memory_order_relaxed)) {
120 op.entry = { routine, name };
121 op.is_addition = false;
122 m_pending_count.fetch_add(1, std::memory_order_relaxed);
123 return true;
124 }
125 }
126
128 "Pending task queue full, could not cancel task '{}'", name);
129 return false;
130}
#define MF_ERROR(comp, ctx,...)
std::atomic< uint32_t > m_pending_count
std::vector< TaskEntry > m_tasks
PendingTaskOp m_pending_ops[MAX_PENDING_TASKS]
std::vector< TaskEntry > m_conditional_tasks
bool cancel_task(const std::shared_ptr< Routine > &routine)
Cancels and removes a task from the scheduler.
std::vector< TaskEntry >::iterator find_task_by_routine(const std::shared_ptr< Routine > &routine)
Find task entry by routine pointer.
@ CoroutineScheduling
Coroutine scheduling and temporal coordination (Vruta::TaskScheduler)
@ Vruta
Coroutines, schedulers, clocks, task management.
@ CONDITIONAL
Condition-driven execution - resume when a caller-supplied predicate returns true.

References cancel_task(), MayaFlux::Vruta::CONDITIONAL, MayaFlux::Journal::CoroutineScheduling, find_task_by_routine(), m_conditional_tasks, m_pending_count, m_pending_ops, m_tasks, MF_ERROR, MayaFlux::Vruta::TaskEntry::routine, and MayaFlux::Journal::Vruta.

Referenced by MayaFlux::Kriya::EventChain::cancel(), MayaFlux::Kriya::Timer::cancel(), MayaFlux::Portal::Forma::Bridge::cancel_inbound(), MayaFlux::Portal::Forma::Bridge::cancel_outbound(), cancel_task(), MayaFlux::Nexus::Fabric::remove(), and MayaFlux::Nexus::Fabric::~Fabric().

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