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

◆ add_task()

void MayaFlux::Vruta::TaskScheduler::add_task ( const std::shared_ptr< Routine > &  routine,
const std::string &  name = "",
bool  initialize = false 
)

Add a routine to the scheduler based on its processing token.

Parameters
routineRoutine to add (SoundRoutine, GraphicsRoutine, or ComplexRoutine)
nameOptional name for the routine (for task management)
initializeWhether to initialize the routine's state immediately

The routine's processing token determines which domain it belongs to and which clock it synchronizes with. Automatically dispatches to the appropriate token-specific task list and clock synchronization.

Definition at line 23 of file Scheduler.cpp.

24{
25 if (!routine) {
26 MF_ERROR(Journal::Component::Vruta, Journal::Context::CoroutineScheduling, "Failed to initiate routine; routine is null. Exiting add_task.");
27 return;
28 }
29
30 std::string task_name = name.empty() ? auto_generate_name(routine) : name;
31 ProcessingToken token = routine->get_processing_token();
32
33 ensure_domain(token);
34
35 if (initialize)
36 initialize_routine_state(routine, token);
37
38 if (token == ProcessingToken::CONDITIONAL) {
39 routine->set_auto_resume(true);
40 for (auto& op : m_conditional_pending_ops) {
41 bool expected = false;
42 if (op.active.compare_exchange_strong(expected, true,
43 std::memory_order_relaxed, std::memory_order_relaxed)) {
44 op.is_addition = true;
45 op.entry = { routine, task_name };
46 m_conditional_pending_count.fetch_add(1, std::memory_order_release);
48 return;
49 }
50 }
52 "Conditional pending queue full, could not add task '{}'", task_name);
53 return;
54 }
55
56 for (auto& op : m_pending_ops) {
57 bool expected = false;
58 if (op.active.compare_exchange_strong(expected, true,
59 std::memory_order_acquire, std::memory_order_relaxed)) {
60 op.entry = { routine, task_name };
61 op.is_addition = true;
62 m_pending_count.fetch_add(1, std::memory_order_relaxed);
63 return;
64 }
65 }
66
68 "Pending task queue full, could not add task '{}'", task_name);
69}
#define MF_ERROR(comp, ctx,...)
bool initialize_routine_state(const std::shared_ptr< Routine > &routine, ProcessingToken token)
Initialize a routine's state for a specific domain.
std::atomic< uint32_t > m_pending_count
std::atomic< uint32_t > m_conditional_pending_count
void start_conditional_thread()
Start the conditional task processing thread if not already running.
std::string auto_generate_name(const std::shared_ptr< Routine > &routine) const
Generate automatic name for a routine based on its type.
PendingTaskOp m_pending_ops[MAX_PENDING_TASKS]
void ensure_domain(ProcessingToken token, unsigned int rate=0)
Initialize a processing domain if it doesn't exist.
PendingTaskOp m_conditional_pending_ops[MAX_PENDING_CONDITIONAL]
void initialize()
Definition main.cpp:11
@ 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 auto_generate_name(), MayaFlux::Vruta::CONDITIONAL, MayaFlux::Journal::CoroutineScheduling, ensure_domain(), initialize(), initialize_routine_state(), m_conditional_pending_count, m_conditional_pending_ops, m_pending_count, m_pending_ops, MF_ERROR, start_conditional_thread(), and MayaFlux::Journal::Vruta.

Referenced by MayaFlux::Kriya::BufferPipeline::dispatch_branch_async(), MayaFlux::Kriya::BufferPipeline::execute_buffer_rate(), MayaFlux::Kriya::BufferPipeline::execute_for_cycles(), MayaFlux::Kriya::BufferPipeline::execute_once(), MayaFlux::Kriya::BufferPipeline::execute_scheduled(), MayaFlux::Kriya::Timer::schedule(), MayaFlux::Portal::Forma::Bridge::spawn_inbound(), MayaFlux::Portal::Forma::Bridge::spawn_sync(), MayaFlux::Kriya::EventChain::start(), MayaFlux::Portal::Forma::Bridge::write(), MayaFlux::Portal::Forma::Bridge::write(), MayaFlux::Portal::Forma::Bridge::write(), and MayaFlux::Portal::Forma::Bridge::write().

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