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:
parent
698bc16ecd
commit
c84bb0d571
2 changed files with 19 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue