diff --git a/kernel/src/scheduler.rs b/kernel/src/scheduler.rs index 97b342f..13c9b9c 100644 --- a/kernel/src/scheduler.rs +++ b/kernel/src/scheduler.rs @@ -1,6 +1,6 @@ use crate::objects::*; use core::ptr::NonNull; -use log::error; +use log::{error, trace}; use spin::lazy::Lazy; use utils::linked_list::Link; @@ -40,19 +40,18 @@ impl Scheduler { pub fn schedule(&self) { while let Some(next) = self.head.next_mut() { - // TODO: also need to check whether it is schedulable - if next.timetick() > 0 { - // Available to run, activate it + if next.timetick() > 0 && next.schedulable() { + trace!("[Scheduler] Switch to {}, tick: {}", next.tid(), next.timetick()); next.activate(); } else if next.timetick() == 0 { - // No time left, refill time tick and move to the end of the queue next.set_timetick(TIME_SLICE); } // put to the end of the queue - // todo: only move blocked and time expired threads to the end - next.link.detach(); - self.head.prepend(next); + if next.timetick() == 0 || !next.schedulable() { + next.link.detach(); + self.head.prepend(next); + } } error!("[Scheduler] No thread to schedule! Where is IDLE thread?");