1
0
Fork 0
mirror of https://gitlab.com/niansa/cosched.git synced 2025-03-06 20:53:26 +01:00

Added Scheduler::run_once()

This commit is contained in:
niansa/tuxifan 2023-05-04 14:27:16 +02:00
parent 698bc16ecd
commit c84bb0d571
2 changed files with 19 additions and 13 deletions

View file

@ -123,7 +123,15 @@ public:
Task::current = tasks.emplace_back(std::make_unique<Task>(this, name)).get();
}
void run();
// Run until there are no more tasks left to process
void run() {
while (!tasks.empty()) {
run_once();
}
}
// Run once
void run_once();
};
}
#endif // _SCHEDULER_HPP

View file

@ -65,19 +65,17 @@ CoSched::Task *CoSched::Scheduler::get_next_task() {
return next_task;
}
void CoSched::Scheduler::run() {
while (!tasks.empty()) {
// If current task isn't sleeping, it is considered a zombie so removed from list
if (Task::current && Task::current->state != TaskState::sleeping) {
delete_task(std::exchange(Task::current, nullptr));
}
// Get new task
Task::current = get_next_task();
// Resume task if any
if (Task::current) Task::current->resume.raise();
void CoSched::Scheduler::run_once() {
// If current task isn't sleeping, it is considered a zombie so removed from list
if (Task::current && Task::current->state != TaskState::sleeping) {
delete_task(std::exchange(Task::current, nullptr));
}
// Get new task
Task::current = get_next_task();
// Resume task if any
if (Task::current) Task::current->resume.raise();
}
thread_local CoSched::Task *CoSched::Task::current;