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

◆ try_resume_with_context()

bool MayaFlux::Vruta::CrossRoutine::try_resume_with_context ( uint64_t  current_value,
DelayContext   
)
overridevirtual

Attempts to resume the coroutine with explicit temporal context.

Parameters
current_valueCurrent position in the timeline (samples, frames, cycles, etc.)
contextThe temporal context being processed
Returns
True if the coroutine was resumed, false otherwise

This context-aware resume method allows different temporal mechanisms to coexist within the same processing token. For example, both sample-based and buffer-cycle-based delays can use SAMPLE_ACCURATE token without interfering with each other.

The default implementation delegates to try_resume(uint64_t) for backward compatibility. Derived classes can override to implement context-specific resumption logic.

Reimplemented from MayaFlux::Vruta::Routine.

Definition at line 468 of file Routine.cpp.

469{
470 if (!is_active())
471 return false;
472
473 auto& promise_ref = m_handle.promise();
474
475 if (promise_ref.should_terminate || !promise_ref.auto_resume) {
476 return false;
477 }
478
479 const DelayContext active = promise_ref.active_delay_context.load(std::memory_order_acquire);
480
481 if (context != DelayContext::NONE && active == DelayContext::AWAIT) {
482 return initialize_state(current_value);
483 }
484
485 if (active != DelayContext::MULTIPLE) {
486 return false;
487 }
488
489 if (context == DelayContext::SAMPLE_BASED) {
490 if (promise_ref.sample_delay_amount > 0
491 && current_value >= promise_ref.next_sample.load(std::memory_order_acquire)) {
492 promise_ref.sample_satisfied.store(true, std::memory_order_release);
493 }
494 } else if (context == DelayContext::FRAME_BASED) {
495 if (promise_ref.frame_delay_amount > 0
496 && current_value >= promise_ref.next_frame.load(std::memory_order_acquire)) {
497 promise_ref.frame_satisfied.store(true, std::memory_order_release);
498 }
499 }
500
501 bool sample_required = promise_ref.sample_delay_amount > 0;
502 bool frame_required = promise_ref.frame_delay_amount > 0;
503
504 if (sample_required && !promise_ref.sample_satisfied.load(std::memory_order_acquire)) {
505 return false;
506 }
507 if (frame_required && !promise_ref.frame_satisfied.load(std::memory_order_acquire)) {
508 return false;
509 }
510
512 if (!promise_ref.active_delay_context.compare_exchange_strong(
513 expected, DelayContext::NONE,
514 std::memory_order_acq_rel, std::memory_order_acquire)) {
515 return false;
516 }
517
518 promise_ref.sample_satisfied.store(false, std::memory_order_release);
519 promise_ref.frame_satisfied.store(false, std::memory_order_release);
520
521 m_handle.resume();
522 return true;
523}
std::coroutine_handle< promise_type > m_handle
Definition Routine.hpp:726
bool initialize_state(uint64_t current_context=0U) override
Initializes the coroutine's state for execution.
Definition Routine.cpp:436
bool is_active() const override
Checks if the coroutine is still active.
Definition Routine.cpp:428
DelayContext
Discriminator for different temporal delay mechanisms.
@ MULTIPLE
Armed on both sample and frame clocks; first to arrive resumes (CrossRoutine)
@ FRAME_BASED
Frame-rate delay (Graphics domain)
@ NONE
No active delay, try resume immediately.
@ SAMPLE_BASED
Sample-accurate delay (audio domain)
@ AWAIT
Awaiter-induced delay (temporary suspension)

References MayaFlux::Vruta::AWAIT, MayaFlux::Vruta::FRAME_BASED, initialize_state(), is_active(), m_handle, MayaFlux::Vruta::MULTIPLE, MayaFlux::Vruta::NONE, and MayaFlux::Vruta::SAMPLE_BASED.

Referenced by try_resume().

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