Implement EINTR for anything using wait_queue

This commit is contained in:
Jeremy Soller
2018-12-22 08:02:00 -07:00
parent 46a6325678
commit ef919f3d52
5 changed files with 18 additions and 10 deletions

View File

@@ -27,6 +27,7 @@ impl<K, V> WaitMap<K, V> where K: Clone + Ord {
if let Some(value) = self.receive_nonblock(key) {
return value;
}
//TODO: use false from wait condition to indicate EINTR
let _ = self.condition.wait();
}
}

View File

@@ -28,20 +28,22 @@ impl<T> WaitQueue<T> {
self.inner.lock().is_empty()
}
pub fn receive(&self) -> T {
pub fn receive(&self) -> Option<T> {
loop {
if let Some(value) = self.inner.lock().pop_front() {
return value;
return Some(value);
}
if ! self.condition.wait() {
return None;
}
let _ = self.condition.wait();
}
}
pub fn receive_into(&self, buf: &mut [T], block: bool) -> usize {
pub fn receive_into(&self, buf: &mut [T], block: bool) -> Option<usize> {
let mut i = 0;
if i < buf.len() && block {
buf[i] = self.receive();
buf[i] = self.receive()?;
i += 1;
}
@@ -57,7 +59,7 @@ impl<T> WaitQueue<T> {
}
}
i
Some(i)
}
pub fn send(&self, value: T) -> usize {