MayaFlux 0.3.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 19 of file Scheduler.cpp.

20{
21 if (!routine) {
22 MF_ERROR(Journal::Component::Vruta, Journal::Context::CoroutineScheduling, "Failed to initiate routine; routine is null. Exiting add_task.");
23 return;
24 }
25
26 std::string task_name = name.empty() ? auto_generate_name(routine) : name;
27 ProcessingToken token = routine->get_processing_token();
28
29 {
30 auto existing_it = find_task_by_name(task_name);
31 if (existing_it != m_tasks.end()) {
32 if (existing_it->routine && existing_it->routine->is_active()) {
33 existing_it->routine->set_should_terminate(true);
34 }
35 m_tasks.erase(existing_it);
36 }
37
38 m_tasks.emplace_back(routine, task_name);
39 }
40
41 if (initialize) {
42 ensure_domain(token);
43 initialize_routine_state(routine, token);
44 } else {
45 ensure_domain(token);
46 }
47}
#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::string auto_generate_name(const std::shared_ptr< Routine > &routine) const
Generate automatic name for a routine based on its type.
std::vector< TaskEntry > m_tasks
std::vector< TaskEntry >::iterator find_task_by_name(const std::string &name)
Find task entry by name.
void ensure_domain(ProcessingToken token, unsigned int rate=0)
Initialize a processing domain if it doesn't exist.
void initialize()
Definition main.cpp:11
@ CoroutineScheduling
Coroutine scheduling and temporal coordination (Vruta::TaskScheduler)
@ Vruta
Coroutines, schedulers, clocks, task management.

References auto_generate_name(), MayaFlux::Journal::CoroutineScheduling, ensure_domain(), find_task_by_name(), initialize(), initialize_routine_state(), m_tasks, MF_ERROR, 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(), and MayaFlux::Kriya::EventChain::start().

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