MayaFlux 1.0.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 481 of file Routine.cpp.

482{
483 if (!is_active())
484 return false;
485
486 auto& promise_ref = m_handle.promise();
487
488 if (promise_ref.should_terminate || !promise_ref.auto_resume) {
489 return false;
490 }
491
492 const DelayContext active = promise_ref.active_delay_context.load(std::memory_order_acquire);
493
494 if (context != DelayContext::NONE && active == DelayContext::AWAIT) {
495 return initialize_state(current_value);
496 }
497
498 if (active != DelayContext::MULTIPLE) {
499 return false;
500 }
501
502 if (context == DelayContext::SAMPLE_BASED) {
503 if (promise_ref.sample_delay_amount > 0
504 && current_value >= promise_ref.next_sample.load(std::memory_order_acquire)) {
505 promise_ref.sample_satisfied.store(true, std::memory_order_release);
506 }
507 } else if (context == DelayContext::FRAME_BASED) {
508 if (promise_ref.frame_delay_amount > 0
509 && current_value >= promise_ref.next_frame.load(std::memory_order_acquire)) {
510 promise_ref.frame_satisfied.store(true, std::memory_order_release);
511 }
512 }
513
514 bool sample_required = promise_ref.sample_delay_amount > 0;
515 bool frame_required = promise_ref.frame_delay_amount > 0;
516
517 if (sample_required && !promise_ref.sample_satisfied.load(std::memory_order_acquire)) {
518 return false;
519 }
520 if (frame_required && !promise_ref.frame_satisfied.load(std::memory_order_acquire)) {
521 return false;
522 }
523
525 if (!promise_ref.active_delay_context.compare_exchange_strong(
526 expected, DelayContext::NONE,
527 std::memory_order_acq_rel, std::memory_order_acquire)) {
528 return false;
529 }
530
531 promise_ref.sample_satisfied.store(false, std::memory_order_release);
532 promise_ref.frame_satisfied.store(false, std::memory_order_release);
533
534 m_handle.resume();
535 return true;
536}
std::coroutine_handle< promise_type > m_handle
Definition Routine.hpp:752
bool initialize_state(uint64_t current_context=0U) override
Initializes the coroutine's state for execution.
Definition Routine.cpp:449
bool is_active() const override
Checks if the coroutine is still active.
Definition Routine.cpp:441
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: