diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index 38520c12a65e57ee3279eda6029bd93c9bde98e5..4c9de51875417f8c014c12199ecd89aae804e08b 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -517,16 +517,10 @@ impl PerCoreScheduler { loop { interrupts::disable(); - if !self.scheduler() { - backoff.reset() - } - // do housekeeping - let wakeup_tasks = self.cleanup_tasks(); + let _ = self.cleanup_tasks(); - // 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 self.ready_queue.is_empty() { if backoff.is_completed() { interrupts::enable_and_wait(); } else { @@ -535,15 +529,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 +628,6 @@ impl PerCoreScheduler { } } } - - false - } else { - status == TaskStatus::Idle } } } diff --git a/src/scheduler/task.rs b/src/scheduler/task.rs index efafe5863def6e04aea4b5c563dace72dad6d40c..88ad9c8632cd89b1a222427310235e300c788a1f 100644 --- a/src/scheduler/task.rs +++ b/src/scheduler/task.rs @@ -296,6 +296,11 @@ impl PriorityTaskQueue { } } + /// Returns true if the queue is empty. + pub fn is_empty(&self) -> bool { + self.prio_bitmap == 0 + } + /// Pop the task with the highest priority from the queue pub fn pop(&mut self) -> Option<Rc<RefCell<Task>>> { if let Some(i) = msb(self.prio_bitmap) {