From 1b95902cb5d6389d02fa5387b8611cd416d7923c Mon Sep 17 00:00:00 2001 From: Stefan Lankes <slankes@eonerc.rwth-aachen.de> Date: Thu, 27 Apr 2023 09:00:54 +0200 Subject: [PATCH] simplify check if a task is available --- src/scheduler/mod.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index 38520c12a..0920a9865 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -517,16 +517,15 @@ impl PerCoreScheduler { loop { interrupts::disable(); - if !self.scheduler() { - backoff.reset() - } - // do housekeeping - let wakeup_tasks = self.cleanup_tasks(); + let _ = self.cleanup_tasks(); + + let still_idle = { + let status = self.current_task.borrow().status; + status == TaskStatus::Idle && self.ready_queue.is_empty() + }; - // Re-enable interrupts and simultaneously set the CPU into the HALT state to only wake up at the next interrupt. - // This atomic operation guarantees that we cannot miss a wakeup interrupt in between. - if !wakeup_tasks { + if still_idle { if backoff.is_completed() { interrupts::enable_and_wait(); } else { @@ -535,15 +534,15 @@ impl PerCoreScheduler { } } else { interrupts::enable(); + self.reschedule(); + backoff.reset(); } } } /// Triggers the scheduler to reschedule the tasks. /// Interrupt flag must be cleared before calling this function. - /// Returns `true` if the new and the old task is the idle task, - /// otherwise the function returns `false`. - pub fn scheduler(&mut self) -> bool { + pub fn scheduler(&mut self) { // Someone wants to give up the CPU // => we have time to cleanup the system let _ = self.cleanup_tasks(); @@ -634,10 +633,6 @@ impl PerCoreScheduler { } } } - - false - } else { - status == TaskStatus::Idle } } } -- GitLab