feat: kernel/objects/tcb: rewrite schedulable and add schedule_next

This commit is contained in:
Paul Pan 2024-09-02 13:58:30 +08:00
parent 60d9b10300
commit 66386aa00b

View File

@ -1,4 +1,5 @@
use crate::arch::{layout::mmap_phys_to_virt, trap::TrapContext, vspace::*};
use crate::scheduler::SCHEDULER;
use crate::syscall::handle_syscall;
use crate::{objects::*, plat::trap::TrapContextOps, vspace::*};
use core::fmt::Debug;
@ -98,7 +99,15 @@ impl TcbObject {
}
pub fn schedulable(&self) -> bool {
self.state != ThreadState::Blocked && self.state != ThreadState::Inactive
match self.state {
ThreadState::Idle | ThreadState::Running => true,
_ => false,
}
}
pub fn schedule_next(&self) {
self.sched_queue.detach();
SCHEDULER.add_next(self);
}
pub fn set_state(&mut self, state: ThreadState) {