Drop context when process exit. Remove util mod.

master
WangRunji 6 years ago
parent 85a1dca684
commit c734f79699

@ -2,6 +2,7 @@
#![feature(alloc)]
#![feature(const_fn)]
#![feature(linkage)]
#![feature(nll)]
extern crate alloc;
#[macro_use]
@ -17,7 +18,6 @@ mod process_manager;
mod processor;
pub mod scheduler;
pub mod thread;
mod util;
mod event_hub;
pub use process_manager::*;

@ -19,8 +19,8 @@ const MAX_PROC_NUM: usize = 32;
pub enum Status {
Ready,
Running(usize),
Waiting(Pid),
Sleeping,
/// aka ZOMBIE. Its context was dropped.
Exited(ExitCode),
}
@ -98,8 +98,10 @@ impl ProcessManager {
proc.status = proc.status_after_stop.clone();
proc.status_after_stop = Status::Ready;
proc.context = Some(context);
if proc.status == Status::Ready {
self.scheduler.lock().insert(pid);
match proc.status {
Status::Ready => self.scheduler.lock().insert(pid),
Status::Exited(_) => proc.context = None,
_ => {}
}
}
@ -121,5 +123,9 @@ impl ProcessManager {
Status::Running(_) => proc.status_after_stop = status,
_ => proc.status = status,
}
match proc.status {
Status::Exited(_) => proc.context = None,
_ => {}
}
}
}

@ -1,15 +0,0 @@
use core::fmt::Debug;
/// Get values by 2 diff keys at the same time
pub trait GetMut2<Idx: Debug + Eq> {
type Output;
fn get_mut(&mut self, id: Idx) -> &mut Self::Output;
fn get_mut2(&mut self, id1: Idx, id2: Idx) -> (&mut Self::Output, &mut Self::Output) {
assert_ne!(id1, id2);
let self1 = self as *mut Self;
let self2 = self1;
let p1 = unsafe { &mut *self1 }.get_mut(id1);
let p2 = unsafe { &mut *self2 }.get_mut(id2);
(p1, p2)
}
}
Loading…
Cancel
Save