diff --git a/crate/thread/src/scheduler/mod.rs b/crate/thread/src/scheduler/mod.rs index 04e56fd..8d6367f 100644 --- a/crate/thread/src/scheduler/mod.rs +++ b/crate/thread/src/scheduler/mod.rs @@ -15,8 +15,6 @@ type Pid = usize; pub trait Scheduler: Sync + 'static { /// Push a thread to the back of ready queue. fn push(&self, pid: Pid); - /// Remove a thread from the ready queue. - fn remove(&self, pid: Pid); /// Select a thread to run, pop it from the queue. fn pop(&self) -> Option; /// Got a tick from CPU. diff --git a/crate/thread/src/scheduler/rr.rs b/crate/thread/src/scheduler/rr.rs index eb79b76..5ff7589 100644 --- a/crate/thread/src/scheduler/rr.rs +++ b/crate/thread/src/scheduler/rr.rs @@ -21,9 +21,6 @@ impl Scheduler for RRScheduler { fn push(&self, pid: usize) { self.inner.lock().push(pid); } - fn remove(&self, pid: usize) { - self.inner.lock().remove(pid); - } fn pop(&self) -> Option { self.inner.lock().pop() } @@ -59,14 +56,6 @@ impl RRSchedulerInner { trace!("rr push {}", pid - 1); } - fn remove(&mut self, pid: Pid) { - let pid = pid + 1; - assert!(self.infos[pid].present); - self.infos[pid].present = false; - self._list_remove(pid); - trace!("rr remove {}", pid - 1); - } - fn pop(&mut self) -> Option { let ret = match self.infos[0].next { 0 => None, diff --git a/crate/thread/src/scheduler/stride.rs b/crate/thread/src/scheduler/stride.rs index 12292a7..c16fcef 100644 --- a/crate/thread/src/scheduler/stride.rs +++ b/crate/thread/src/scheduler/stride.rs @@ -38,9 +38,6 @@ impl Scheduler for StrideScheduler { fn push(&self, pid: usize) { self.inner.lock().push(pid); } - fn remove(&self, pid: usize) { - self.inner.lock().remove(pid); - } fn pop(&self) -> Option { self.inner.lock().pop() } @@ -76,24 +73,6 @@ impl StrideSchedulerInner { trace!("stride push {}", pid); } - fn remove(&mut self, pid: Pid) { - let info = &mut self.infos[pid]; - assert!(info.present); - info.present = false; - if self.queue.peek().is_some() && self.queue.peek().unwrap().1 == pid { - self.queue.pop(); - } else { - // BinaryHeap only support pop the top. - // So in order to remove an arbitrary element, - // we have to take all elements into a Vec, - // then push the rest back. - let rest: Vec<_> = self.queue.drain().filter(|&p| p.1 != pid).collect(); - use core::iter::FromIterator; - self.queue = BinaryHeap::from_iter(rest.into_iter()); - } - trace!("stride remove {}", pid); - } - fn pop(&mut self) -> Option { let ret = self.queue.pop().map(|(_, pid)| pid); if let Some(pid) = ret { diff --git a/crate/thread/src/thread_pool.rs b/crate/thread/src/thread_pool.rs index 487dc77..6b05b58 100644 --- a/crate/thread/src/thread_pool.rs +++ b/crate/thread/src/thread_pool.rs @@ -135,7 +135,7 @@ impl ThreadPool { trace!("process {} {:?} -> {:?}", tid, proc.status, status); match (&proc.status, &status) { (Status::Ready, Status::Ready) => return, - (Status::Ready, _) => self.scheduler.remove(tid), + (Status::Ready, _) => panic!("can not remove a process from ready queue"), (Status::Exited(_), _) => panic!("can not set status for a exited process"), (Status::Sleeping, Status::Exited(_)) => self.timer.lock().stop(Event::Wakeup(tid)), (_, Status::Ready) => self.scheduler.push(tid),