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

◆ terminate_all_tasks()

void MayaFlux::Vruta::TaskScheduler::terminate_all_tasks ( )

Terminate and clear all tasks.

Submissions made while this runs, including from completion callbacks, are rejected. Must not be called from the conditional worker thread or from a callback fired during a queue drain; such calls are ignored. New tasks are accepted again once this returns, or if any step throws.

Definition at line 596 of file Scheduler.cpp.

597{
598 if (m_conditional_thread.joinable() && m_conditional_thread.get_id() == std::this_thread::get_id()) {
599 return;
600 }
601
602 if (t_draining == this) {
604 "terminate_all_tasks ignored: called from a callback during a queue drain");
605 return;
606 }
607
608 if (m_terminating.exchange(true)) {
609 return;
610 }
611 TerminationScope terminating(m_terminating);
612
613 while (m_inflight_submissions.load() != 0) {
614 std::this_thread::yield();
615 }
616
617 if (m_conditional_thread.joinable()) {
618 m_conditional_thread.request_stop();
620 }
621
624
625 for (auto& entry : m_tasks) {
626 if (entry.routine && entry.routine->is_active()) {
627 entry.routine->set_should_terminate(true);
628 }
629 }
630
631 for (auto& entry : m_tasks) {
632 if (entry.routine && entry.routine->is_active()) {
633 entry.routine->force_resume();
634 }
635 }
636
637 constexpr int MAX_ATTEMPTS = 3;
638 for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
639 std::this_thread::sleep_for(std::chrono::milliseconds(5));
640
641 bool any_active = false;
642 for (auto& entry : m_tasks) {
643 if (entry.routine && entry.routine->is_active()) {
644 any_active = true;
645 entry.routine->force_resume();
646 }
647 }
648
649 if (!any_active) {
650 break;
651 }
652 }
653
654 bool all_done = true;
655 for (const auto& entry : m_tasks) {
656 if (entry.routine && entry.routine->is_active()) {
657 all_done = false;
659 "Coroutine '{}' stuck after {} attempts - forcing destruction",
660 entry.name, MAX_ATTEMPTS);
661 }
662 }
663
664 if (!all_done) {
666 "Some coroutines did not complete - forcing destruction");
667 } else {
669 "All coroutines terminated successfully");
670 }
671
672 for (auto& entry : m_conditional_tasks) {
673 if (entry.routine && entry.routine->is_active())
674 entry.routine->set_should_terminate(true);
675 }
676 for (auto& entry : m_conditional_tasks) {
677 if (entry.routine && entry.routine->is_active())
678 entry.routine->force_resume();
679 }
680 m_conditional_tasks.clear();
681
682 m_tasks.clear();
683}
#define MF_INFO(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::atomic< bool > m_terminating
std::vector< TaskEntry > m_tasks
std::vector< TaskEntry > m_conditional_tasks
void drain_pending_tasks()
Drain pending task operations (additions/removals) before processing.
std::atomic< uint32_t > m_inflight_submissions
void drain_conditional_pending()
Drain pending conditional task operations before processing.
@ CoroutineScheduling
Coroutine scheduling and temporal coordination (Vruta::TaskScheduler)
@ Vruta
Coroutines, schedulers, clocks, task management.
std::atomic< bool > terminating
Definition Core.cpp:22

References MayaFlux::Journal::CoroutineScheduling, drain_conditional_pending(), drain_pending_tasks(), m_conditional_tasks, m_conditional_thread, m_inflight_submissions, m_tasks, m_terminating, MF_INFO, MF_WARN, and MayaFlux::Journal::Vruta.

+ Here is the call graph for this function: