Skip to content

Commit

Permalink
add a sleep-if-idle implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Blindspot22 committed Aug 10, 2024
1 parent 7c8b608 commit a9bd3a1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/task/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl Executor {
pub fn run(&mut self) -> ! {
loop {
self.run_ready_tasks();
self.sleep_if_idle();
}
}

Expand All @@ -32,6 +33,17 @@ impl Executor {
self.task_queue.push(task_id).expect("queue full");
}

fn sleep_if_idle(&self) {
use x86_64::instructions::interrupts::{self, enable_and_hlt};

interrupts::disable();
if self.task_queue.is_empty() {
enable_and_hlt();
} else {
interrupts::enable();
}
}

fn run_ready_tasks(&mut self) {
// destructure `self` to avoid borrow checker errors
let Self {
Expand Down

0 comments on commit a9bd3a1

Please sign in to comment.