12 TaskEntry(
const std::shared_ptr<Routine>& r, std::string n)
61 TaskScheduler(uint32_t default_sample_rate = 48000, uint32_t default_frame_rate = 60);
73 void add_task(
const std::shared_ptr<Routine>& routine,
const std::string& name =
"",
bool initialize =
false);
80 std::shared_ptr<Routine> get_task(
const std::string& name)
const;
91 bool cancel_task(
const std::shared_ptr<Routine>& routine);
112 std::vector<std::shared_ptr<Routine>> get_tasks_for_token(
ProcessingToken token)
const;
123 void process_token(
ProcessingToken token, uint64_t processing_units = 1);
132 void process_all_tokens();
158 uint64_t current_units(
ProcessingToken token = ProcessingToken::SAMPLE_ACCURATE)
const;
165 unsigned int get_rate(
ProcessingToken token = ProcessingToken::SAMPLE_ACCURATE)
const;
186 return get_typed_clock<SampleClock>(ProcessingToken::SAMPLE_ACCURATE);
214 template <
typename ClockType>
217 return dynamic_cast<const ClockType&
>(get_clock(token));
227 template <
typename... Args>
230 auto it = find_task_by_name(name);
231 if (it != m_tasks.end() && it->routine && it->routine->is_active()) {
232 it->routine->update_params(std::forward<Args>(args)...);
245 template <
typename T>
248 auto it = find_task_by_name(name);
249 if (it != m_tasks.end() && it->routine && it->routine->is_active()) {
250 return it->routine->get_state<T>(state_key);
262 template <
typename T>
265 return [
this, name, state_key]() -> T {
266 if (
auto value = get_task_state<T>(name, state_key)) {
277 uint64_t get_next_task_id()
const;
295 void pause_all_tasks();
300 void resume_all_tasks();
305 void terminate_all_tasks();
329 return m_current_buffer_cycle;
338 m_current_buffer_cycle++;
341 void process_buffer_cycle_tasks();
349 std::string auto_generate_name(
const std::shared_ptr<Routine>& routine)
const;
356 std::vector<TaskEntry>::iterator find_task_by_name(
const std::string& name);
363 std::vector<TaskEntry>::const_iterator find_task_by_name(
const std::string& name)
const;
370 std::vector<TaskEntry>::iterator find_task_by_routine(
const std::shared_ptr<Routine>& routine);
391 void process_default(
ProcessingToken token, uint64_t processing_units);
396 void cleanup_completed_tasks();
403 bool initialize_routine_state(
const std::shared_ptr<Routine>& routine,
ProcessingToken token);
432 mutable std::atomic<uint64_t> m_next_task_id { 1 };
453 uint64_t m_current_buffer_cycle {};
455 uint64_t m_registered_sample_rate { 48000 };
456 uint32_t m_registered_frame_rate { 60 };
Abstract base interface for all clock types in the multimodal scheduling system.
Sample-accurate timing system for audio processing domain.
std::function< T()> create_value_accessor(const std::string &name, const std::string &state_key) const
Create value accessor function for named task.
uint64_t get_current_buffer_cycle() const
Get current buffer cycle for task scheduling Updated by AudioSubsystem at each buffer boundary.
SampleClock m_clock
The master sample clock for the processing engine.
uint32_t get_cleanup_threshold() const
Get the task cleanup threshold.
std::unordered_map< ProcessingToken, unsigned int > m_token_rates
Default processing rates for each domain.
std::vector< TaskEntry > m_tasks
void tick_buffer_cycle()
Increment buffer cycle counter Called by AudioSubsystem at start of each buffer processing.
const SampleClock & get_sample_clock() const
Get the audio domain's SampleClock (legacy interface)
uint32_t m_cleanup_threshold
Threshold for task cleanup.
std::unordered_map< ProcessingToken, token_processing_func_t > m_token_processors
Custom processors for specific domains.
bool update_task_params(const std::string &name, Args &&... args)
Update parameters of a named task.
T * get_task_state(const std::string &name, const std::string &state_key) const
Get task state value by name and key.
const ClockType & get_typed_clock(ProcessingToken token=ProcessingToken::SAMPLE_ACCURATE) const
Get a typed clock for a specific processing domain.
std::vector< std::string > get_task_names() const
Get all task names for debugging/inspection.
void set_cleanup_threshold(uint32_t threshold)
Set the task cleanup threshold.
std::unordered_map< ProcessingToken, std::unique_ptr< IClock > > m_token_clocks
Clock instances for each processing domain.
const SampleClock & get_clock() const
Gets the primary clock (audio domain for legacy compatibility)
Token-based multimodal task scheduling system for unified coroutine processing.
std::function< void(const std::vector< std::shared_ptr< Routine > > &, uint64_t)> token_processing_func_t
Function type for processing tasks in a specific token domain.
uint64_t seconds_to_units(double seconds, uint32_t rate)
Convert seconds to processing units for any rate.
bool restart_task(const std::string &name)
Restarts a scheduled task.
uint64_t seconds_to_samples(double seconds)
Converts a time duration in seconds to the equivalent number of audio samples.
bool cancel_task(const std::string &name)
Cancels a scheduled task.
std::shared_ptr< Routine > routine
TaskEntry(const std::shared_ptr< Routine > &r, std::string n)