Terminate and clear all tasks.
507{
509
511 if (entry.routine && entry.routine->is_active()) {
512 entry.routine->set_should_terminate(true);
513 }
514 }
515
517 if (entry.routine && entry.routine->is_active()) {
518 entry.routine->force_resume();
519 }
520 }
521
522 constexpr int MAX_ATTEMPTS = 3;
523 for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
524 std::this_thread::sleep_for(std::chrono::milliseconds(5));
525
526 bool any_active = false;
528 if (entry.routine && entry.routine->is_active()) {
529 any_active = true;
530 entry.routine->force_resume();
531 }
532 }
533
534 if (!any_active) {
535 break;
536 }
537 }
538
539 bool all_done = true;
540 for (
const auto& entry :
m_tasks) {
541 if (entry.routine && entry.routine->is_active()) {
542 all_done = false;
544 "Coroutine '{}' stuck after {} attempts - forcing destruction",
545 entry.name, MAX_ATTEMPTS);
546 }
547 }
548
549 if (!all_done) {
551 "Some coroutines did not complete - forcing destruction");
552 } else {
554 "All coroutines terminated successfully");
555 }
556
559 if (entry.routine && entry.routine->is_active())
560 entry.routine->set_should_terminate(true);
561 }
563 if (entry.routine && entry.routine->is_active())
564 entry.routine->force_resume();
565 }
567
569}
#define MF_LOG(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::vector< TaskEntry > m_tasks
std::vector< TaskEntry > m_conditional_tasks
void drain_pending_tasks()
Drain pending task operations (additions/removals) before processing.
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.