MayaFlux 1.0.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 94 of file Scheduler.cpp.

95{
96 if (!routine) {
97 MF_ERROR(Journal::Component::Vruta, Journal::Context::CoroutineScheduling, "Failed to initiate routine; routine is null. Exiting add_task.");
98 return;
99 }
100
101 SubmissionGuard guard(m_inflight_submissions, m_terminating);
102 if (!guard.accepted) {
104 "Rejected task '{}': scheduler is terminating", name);
105 return;
106 }
107
108 std::string task_name = name.empty() ? auto_generate_name(routine) : name;
109 ProcessingToken token = routine->get_processing_token();
110
111 ensure_domain(token);
112
113 if (initialize)
114 initialize_routine_state(routine, token);
115
116 if (token == ProcessingToken::CONDITIONAL) {
117 routine->set_auto_resume(true);
118 for (auto& op : m_conditional_pending_ops) {
119 bool expected = false;
120 if (op.active.compare_exchange_strong(expected, true,
121 std::memory_order_relaxed, std::memory_order_relaxed)) {
122 op.is_addition = true;
123 op.entry = { routine, task_name };
124 m_conditional_pending_count.fetch_add(1, std::memory_order_release);
126 return;
127 }
128 }
130 "Conditional pending queue full, could not add task '{}'", task_name);
131 return;
132 }
133
134 for (auto& op : m_pending_ops) {
135 bool expected = false;
136 if (op.active.compare_exchange_strong(expected, true,
137 std::memory_order_acquire, std::memory_order_relaxed)) {
138 op.entry = { routine, task_name };
139 op.is_addition = true;
140 m_pending_count.fetch_add(1, std::memory_order_relaxed);
141 return;
142 }
143 }
144
146 "Pending task queue full, could not add task '{}'", task_name);
147}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::string name
Definition VKDevice.cpp:123
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< bool > m_terminating
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.
std::atomic< uint32_t > m_inflight_submissions
PendingTaskOp m_conditional_pending_ops[MAX_PENDING_CONDITIONAL]
void initialize()
Definition main.cpp:10
@ 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_inflight_submissions, m_pending_count, m_pending_ops, m_terminating, MF_ERROR, MF_WARN, name, start_conditional_thread(), and MayaFlux::Journal::Vruta.

Referenced by MayaFlux::Kriya::BufferPipeline::dispatch_branch_async(), MayaFlux::Kriya::BufferPipeline::dispatch_frame_branch(), MayaFlux::Kriya::BufferPipeline::execute_buffer_rate(), MayaFlux::Kriya::BufferPipeline::execute_for_cycles(), MayaFlux::Kriya::BufferPipeline::execute_frame_rate(), 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::IO::SpatialCapture::start(), MayaFlux::IO::VolumeCapture::start(), MayaFlux::Portal::Forma::Bridge::write(), MayaFlux::Portal::Forma::Bridge::write(), MayaFlux::Portal::Forma::Bridge::write(), MayaFlux::Portal::Forma::Bridge::write(), MayaFlux::Portal::Forma::Bridge::write_aggregate(), and MayaFlux::Portal::Forma::Bridge::write_assembled_data().

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