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);
}
}
+18 -14
View File
@@ -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)
}
};