MayaFlux 0.4.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.

Definition at line 506 of file Scheduler.cpp.

507{
509
510 for (auto& entry : m_tasks) {
511 if (entry.routine && entry.routine->is_active()) {
512 entry.routine->set_should_terminate(true);
513 }
514 }
515
516 for (auto& entry : m_tasks) {
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;
527 for (auto& entry : m_tasks) {
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
558 for (auto& entry : m_conditional_tasks) {
559 if (entry.routine && entry.routine->is_active())
560 entry.routine->set_should_terminate(true);
561 }
562 for (auto& entry : m_conditional_tasks) {
563 if (entry.routine && entry.routine->is_active())
564 entry.routine->force_resume();
565 }
566 m_conditional_tasks.clear();
567
568 m_tasks.clear();
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.

References MayaFlux::Journal::CoroutineScheduling, drain_conditional_pending(), drain_pending_tasks(), m_conditional_tasks, m_tasks, MF_LOG, MF_WARN, and MayaFlux::Journal::Vruta.

+ Here is the call graph for this function: