diff --git a/src/task/executor.rs b/src/task/executor.rs index c7211d79..51aa8636 100644 --- a/src/task/executor.rs +++ b/src/task/executor.rs @@ -32,6 +32,7 @@ impl Executor { loop { self.wake_tasks(); self.run_ready_tasks(); + self.sleep_if_idle(); } } @@ -65,6 +66,22 @@ impl Executor { } } + fn sleep_if_idle(&self) { + use x86_64::instructions::interrupts::{self, enable_interrupts_and_hlt}; + + // fast path + if !self.wake_queue.is_empty() { + return; + } + + interrupts::disable(); + if self.wake_queue.is_empty() { + enable_interrupts_and_hlt(); + } else { + interrupts::enable(); + } + } + fn create_waker(&self, task_id: TaskId) -> Waker { Waker::from(Arc::new(TaskWaker { task_id,