|
|
@ -131,14 +131,14 @@ impl ThreadPool {
|
|
|
|
/// Insert/Remove it to/from scheduler if necessary.
|
|
|
|
/// Insert/Remove it to/from scheduler if necessary.
|
|
|
|
fn set_status(&self, tid: Tid, status: Status) {
|
|
|
|
fn set_status(&self, tid: Tid, status: Status) {
|
|
|
|
let mut proc_lock = self.threads[tid].lock();
|
|
|
|
let mut proc_lock = self.threads[tid].lock();
|
|
|
|
let mut proc = proc_lock.as_mut().expect("process not exist");
|
|
|
|
if let Some(mut proc) = proc_lock.as_mut() {
|
|
|
|
trace!("process {} {:?} -> {:?}", tid, proc.status, status);
|
|
|
|
trace!("process {} {:?} -> {:?}", tid, proc.status, status);
|
|
|
|
match (&proc.status, &status) {
|
|
|
|
match (&proc.status, &status) {
|
|
|
|
(Status::Ready, Status::Ready) => return,
|
|
|
|
(Status::Ready, Status::Ready) => return,
|
|
|
|
(Status::Ready, _) => panic!("can not remove a process from ready queue"),
|
|
|
|
(Status::Ready, _) => panic!("can not remove a process from ready queue"),
|
|
|
|
(Status::Exited(_), _) => panic!("can not set status for a exited process"),
|
|
|
|
(Status::Exited(_), _) => panic!("can not set status for a exited process"),
|
|
|
|
(Status::Sleeping, Status::Exited(_)) => self.timer.lock().stop(Event::Wakeup(tid)),
|
|
|
|
(Status::Sleeping, Status::Exited(_)) => self.timer.lock().stop(Event::Wakeup(tid)),
|
|
|
|
(Status::Running(_), Status::Ready) => {} // to stop a thread, use stop() intead
|
|
|
|
(Status::Running(_), Status::Ready) => {} // process will be added to scheduler in stop()
|
|
|
|
(_, Status::Ready) => self.scheduler.push(tid),
|
|
|
|
(_, Status::Ready) => self.scheduler.push(tid),
|
|
|
|
_ => {}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -151,6 +151,7 @@ impl ThreadPool {
|
|
|
|
_ => {}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_status(&self, tid: Tid) -> Option<Status> {
|
|
|
|
pub fn get_status(&self, tid: Tid) -> Option<Status> {
|
|
|
|
self.threads[tid].lock().as_ref().map(|p| p.status.clone())
|
|
|
|
self.threads[tid].lock().as_ref().map(|p| p.status.clone())
|
|
|
|