Terminate and clear all tasks.
499{
501
503 if (entry.routine && entry.routine->is_active()) {
504 entry.routine->set_should_terminate(true);
505 }
506 }
507
509 if (entry.routine && entry.routine->is_active()) {
510 entry.routine->force_resume();
511 }
512 }
513
514 constexpr int MAX_ATTEMPTS = 3;
515 for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
516 std::this_thread::sleep_for(std::chrono::milliseconds(5));
517
518 bool any_active = false;
520 if (entry.routine && entry.routine->is_active()) {
521 any_active = true;
522 entry.routine->force_resume();
523 }
524 }
525
526 if (!any_active) {
527 break;
528 }
529 }
530
531 bool all_done = true;
532 for (
const auto& entry :
m_tasks) {
533 if (entry.routine && entry.routine->is_active()) {
534 all_done = false;
536 "Coroutine '{}' stuck after {} attempts - forcing destruction",
537 entry.name, MAX_ATTEMPTS);
538 }
539 }
540
541 if (!all_done) {
543 "Some coroutines did not complete - forcing destruction");
544 } else {
546 "All coroutines terminated successfully");
547 }
548
551 if (entry.routine && entry.routine->is_active())
552 entry.routine->set_should_terminate(true);
553 }
555 if (entry.routine && entry.routine->is_active())
556 entry.routine->force_resume();
557 }
559
561}
#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.