Allow waitpid to be interrupted.
This commit is contained in:
@@ -26,14 +26,15 @@ where
|
||||
self.inner.lock().remove(key)
|
||||
}
|
||||
|
||||
pub fn receive(&self, key: &K, reason: &'static str) -> V {
|
||||
pub fn receive(&self, key: &K, reason: &'static str) -> Option<V> {
|
||||
loop {
|
||||
let mut inner = self.inner.lock();
|
||||
if let Some(value) = inner.remove(key) {
|
||||
return value;
|
||||
return Some(value);
|
||||
}
|
||||
if !self.condition.wait(inner, reason) {
|
||||
return None;
|
||||
}
|
||||
//TODO: use false from wait condition to indicate EINTR
|
||||
let _ = self.condition.wait(inner, reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-14
@@ -674,13 +674,15 @@ pub fn waitpid(
|
||||
Some(Ok(ProcessId::from(0)))
|
||||
}
|
||||
} else {
|
||||
let (w_pid, status) = waitpid.receive(
|
||||
&WaitpidKey {
|
||||
pid: None,
|
||||
pgid: Some(pgid),
|
||||
},
|
||||
"waitpid pgid",
|
||||
);
|
||||
let (w_pid, status) = waitpid
|
||||
.receive(
|
||||
&WaitpidKey {
|
||||
pid: None,
|
||||
pgid: Some(pgid),
|
||||
},
|
||||
"waitpid pgid",
|
||||
)
|
||||
.ok_or(Error::new(EINTR))?;
|
||||
grim_reaper(w_pid, status)
|
||||
}
|
||||
} else {
|
||||
@@ -716,13 +718,15 @@ pub fn waitpid(
|
||||
Some(Ok(ProcessId::from(0)))
|
||||
}
|
||||
} else {
|
||||
let (w_pid, status) = waitpid.receive(
|
||||
&WaitpidKey {
|
||||
pid: Some(pid),
|
||||
pgid: None,
|
||||
},
|
||||
"waitpid pid",
|
||||
);
|
||||
let (w_pid, status) = waitpid
|
||||
.receive(
|
||||
&WaitpidKey {
|
||||
pid: Some(pid),
|
||||
pgid: None,
|
||||
},
|
||||
"waitpid pid",
|
||||
)
|
||||
.ok_or(Error::new(EINTR))?;
|
||||
grim_reaper(w_pid, status)
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user