36template <
typename RoutineType>
41 completion_callback = std::move(
callback);
42 completion_registered.store(
static_cast<bool>(completion_callback));
43 if (completion_signaled.load())
49 should_terminate.store(
value, std::memory_order_release);
56 completion_signaled.store(
true);
57 if (!completion_registered.load() || completion_notified.exchange(
true))
76 return RoutineType(std::coroutine_handle<routine_promise>::from_promise(*
this));
128 bool auto_resume =
true;
137 std::atomic<bool> should_terminate {
false };
139 std::atomic<bool> completion_signaled {
false };
140 std::atomic<bool> completion_registered {
false };
141 std::atomic<bool> completion_notified {
false };
156 std::unordered_map<std::string, std::any>
state;
164 const bool sync_to_clock =
false;
172 uint64_t delay_amount = 0;
182 template <
typename T>
185 state[key] = std::make_any<T>(std::move(
value));
197 template <
typename T>
200 auto it = state.find(key);
201 if (it != state.end()) {
203 return std::any_cast<T>(&it->second);
204 }
catch (
const std::bad_any_cast&) {
213 set_state(
"domain_error", awaiter_name +
": " + suggestion);
214 should_terminate =
true;
253 bool sync_to_clock =
true;
262 uint64_t next_sample = 0;
269 uint64_t next_buffer_cycle = 0;
322 bool sync_to_clock =
true;
337 uint64_t next_frame = 0;
372 uint64_t delay_amount = 0;
404 bool sync_to_clock =
true;
412 std::atomic<uint64_t> next_sample { 0 };
420 std::atomic<uint64_t> next_frame { 0 };
433 std::atomic<DelayContext> active_delay_context { DelayContext::NONE };
441 uint64_t sample_delay_amount { 0 };
449 uint64_t frame_delay_amount { 0 };
457 std::atomic<bool> sample_satisfied {
false };
465 std::atomic<bool> frame_satisfied {
false };
505 std::atomic<bool> armed {
false };
517 Event get_return_object();
527 void own(std::shared_ptr<Vruta::NetworkSource> source)
529 owned_sources.push_back(std::move(source));
Coroutine resumed by more than one clock.
Coroutine type for event-driven suspension.
Coroutine resumed when a caller-supplied condition becomes true.
A C++20 coroutine-based graphics processing task with frame-accurate timing.
A C++20 coroutine-based audio processing task with sample-accurate timing.
MAYAFLUX_API void invoke_routine_completion(std::function< void()> callback) noexcept
DelayContext
Discriminator for different temporal delay mechanisms.
Coroutine promise type for audio processing tasks with sample-accurate timing.
std::function< bool()> condition
Condition evaluated by the scheduler thread on each iteration.
Coroutine promise for routines suspended on an arbitrary boolean condition.
Coroutine promise for routines resumed by more than one clock.
void own(std::shared_ptr< Vruta::NetworkSource > source)
Transfer ownership of a NetworkSource to this coroutine frame.
std::vector< std::shared_ptr< Vruta::NetworkSource > > owned_sources
Coroutine-owned NetworkSource instances.
Coroutine promise type for graphics processing tasks with frame-accurate timing.
void await_resume() const noexcept
void await_suspend(std::coroutine_handle<>) const noexcept
routine_promise * promise
bool await_ready() const noexcept
void unhandled_exception()
Handles exceptions thrown from within the coroutine.
void domain_mismatch_error(const std::string &awaiter_name, const std::string &suggestion)
void on_complete(std::function< void()> callback)
void notify_complete() noexcept
void set_state(const std::string &key, T value)
Stores a value in the state dictionary.
RoutineType get_return_object()
T * get_state(const std::string &key)
Retrieves a value from the state dictionary.
void set_should_terminate(bool value) noexcept
void return_void()
Handles the coroutine's void return.
std::unordered_map< std::string, std::any > state
Dictionary for storing arbitrary state data.
std::suspend_never initial_suspend()
Determines whether the coroutine suspends immediately upon creation.
std::function< void()> completion_callback
CompletionAwaiter final_suspend() noexcept
Determines whether the coroutine suspends before destruction.
Base coroutine promise type for audio processing tasks.