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.
597{
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
609 return;
610 }
612
614 std::this_thread::yield();
615 }
616
620 }
621
624
626 if (entry.routine && entry.routine->is_active()) {
627 entry.routine->set_should_terminate(true);
628 }
629 }
630
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;
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
673 if (entry.routine && entry.routine->is_active())
674 entry.routine->set_should_terminate(true);
675 }
677 if (entry.routine && entry.routine->is_active())
678 entry.routine->force_resume();
679 }
681
683}
#define MF_INFO(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::atomic< bool > m_terminating
std::jthread m_conditional_thread
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