Allow waitpid to be interrupted.

This commit is contained in:
4lDO2
2024-07-20 23:17:31 +02:00
parent 005635083d
commit 51c4be10e0
2 changed files with 23 additions and 18 deletions
+5 -4
View File
@@ -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);
}
}