MayaFlux 0.5.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 498 of file Scheduler.cpp.

499{
501
502 for (auto& entry : m_tasks) {
503 if (entry.routine && entry.routine->is_active()) {
504 entry.routine->set_should_terminate(true);
505 }
506 }
507
508 for (auto& entry : m_tasks) {
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;
519 for (auto& entry : m_tasks) {
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
550 for (auto& entry : m_conditional_tasks) {
551 if (entry.routine && entry.routine->is_active())
552 entry.routine->set_should_terminate(true);
553 }
554 for (auto& entry : m_conditional_tasks) {
555 if (entry.routine && entry.routine->is_active())
556 entry.routine->force_resume();
557 }
558 m_conditional_tasks.clear();
559
560 m_tasks.clear();
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.

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: