Put the CPU to sleep when no task is ready

This commit is contained in:
Philipp Oppermann
2020-03-27 17:17:34 +01:00
parent 50b4b89ac2
commit e465c5b278

View File

@@ -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,