Implement the typical use of waitpid

This commit is contained in:
Jeremy Soller 2016-09-16 18:50:47 -06:00
parent e680a84a57
commit 3e726a5d0d
6 changed files with 146 additions and 101 deletions

View file

@ -363,3 +363,27 @@ pub fn sched_yield() -> Result<usize> {
unsafe { context::switch(); }
Ok(0)
}
pub fn waitpid(pid: usize, _status_ptr: usize, _options: usize) -> Result<usize> {
loop {
{
let mut exited = false;
{
let contexts = context::contexts();
let context_lock = contexts.get(pid).ok_or(Error::NoProcess)?;
let context = context_lock.read();
if context.status == context::Status::Exited {
exited = true;
}
}
if exited {
let mut contexts = context::contexts_mut();
return contexts.remove(pid).ok_or(Error::NoProcess).and(Ok(pid));
}
}
unsafe { context::switch(); }
}
}