no longer support 'remove' in Scheduler

master
WangRunji 6 years ago
parent a224e85c8d
commit 5a1b3e0dff

@ -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<Pid>;
/// Got a tick from CPU.

@ -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<usize> {
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<Pid> {
let ret = match self.infos[0].next {
0 => None,

@ -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<usize> {
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<Pid> {
let ret = self.queue.pop().map(|(_, pid)| pid);
if let Some(pid) = ret {

@ -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),

Loading…
Cancel
Save