mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: scheduler: implement schedule
This commit is contained in:
parent
ecb8b7a54f
commit
6565beef4c
@ -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,20 +40,19 @@ 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
|
||||
if next.timetick() == 0 || !next.schedulable() {
|
||||
next.link.detach();
|
||||
self.head.prepend(next);
|
||||
}
|
||||
}
|
||||
|
||||
error!("[Scheduler] No thread to schedule! Where is IDLE thread?");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user