Commit c6bd772f authored by Nifou's avatar Nifou

Add an IDLE function when there is no process running

parent 1d914fce
......@@ -15,7 +15,7 @@
* along with this program. If not, see https://www.gnu.org/licenses.
*/
//! Syscalls used for tasking (exit, ...)
use crate::tasking::scheduler::exit;
use crate::tasking::scheduler::kill;
use super::Syscall;
impl<'a> Syscall<'a> {
......@@ -25,7 +25,7 @@ impl<'a> Syscall<'a> {
0 => println!("Exit success"),
_ => println!("Error"),
}
exit(None);
kill();
0
}
}
......@@ -49,6 +49,13 @@ impl Scheduler {
return Some(i);
}
}
// If there is no process, try with the first
if self.threads[0].state == ProcessState::Alive {
return Some(0);
}
// IDLE process
None
}
......@@ -57,6 +64,13 @@ impl Scheduler {
&mut self.threads[self.current_thread.unwrap()]
}
/// An IDLE function which does nothing!
fn idle(&self) {
loop {
unsafe { llvm_asm!("sti; hlt; cli"); }
}
}
/// Switch to the next process
pub fn tick(&mut self, saved: Option<(u64, u64)>) {
// Use the kernel's page table
......@@ -66,7 +80,13 @@ impl Scheduler {
if self.current_thread.is_some() {
let current_thread = self.current_thread.unwrap();
self.threads[current_thread].ctx.save(saved);
self.current_thread = Some(self.find_next_process(current_thread).unwrap_or(0));
if let Some(thread) = self.find_next_process(current_thread) {
self.current_thread = Some(thread);
}
else {
self.idle();
}
} else {
// If the scheduler is switching for the first time, do not save the context
self.current_thread = Some(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment