feat: scheduler: implement schedule

This commit is contained in:
Paul Pan 2024-06-15 19:59:52 +08:00
parent ecb8b7a54f
commit 6565beef4c

View File

@ -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?");