[pdpix] Enhancement: Rework wait to just call wait_any.
@@ -166,36 +166,18 @@ impl LibOS {
}
}
- /// Waits for a pending operation in an I/O queue.
+ /// Waits for a pending I/O operation to complete or a timeout to expire.
+ /// This is just a single-token convenience wrapper for wait_any().
pub fn wait(&mut self, qt: QToken, timeout: Option<Duration>) -> Result<demi_qresult_t, Fail> {
trace!("wait(): qt={:?}, timeout={:?}", qt, timeout);
- // Retrieve associated schedule handle.
- let mut handle: SchedulerHandle = self.schedule(qt)?;
-
- // Get the wait start time, but only if we have a timeout. We don't care when we started if we wait forever.
- let start: Option<Instant> = if timeout.is_none() { None } else { Some(Instant::now()) };
-
- loop {
- // Poll first, so as to give pending operations a chance to complete.
- self.poll();
-
- // The operation has completed, so extract the result and return.
- if handle.has_completed() {
- return Ok(self.pack_result(handle, qt)?);
- }
+ // Put the QToken into a single element array.
+ let qt_array: [QToken; 1] = [qt];
- // If we have a timeout, check for expiration.
- if timeout.is_some()
- && Instant::now().duration_since(start.expect("start should be set if timeout is"))
- > timeout.expect("timeout should still be set")
- {
- // Return this operation to the scheduling queue by removing the associated key
- // (which would otherwise cause the operation to be freed).
- handle.take_key();
- return Err(Fail::new(libc::ETIMEDOUT, "timer expired"));
- }
- }
+ // Call wait_any() to do the real work.
+ let result = self.wait_any(&qt_array, timeout)?;
+ debug_assert_eq!(result.0, 0);
+ Ok(result.1)
}
/// Waits for an I/O operation to complete or a timeout to expire.
@@ -223,7 +205,7 @@ impl LibOS {
}
}
- /// Waits for any operation in an I/O queue.
+ /// Waits for any of the given pending I/O operations to complete or a timeout to expire.
pub fn wait_any(&mut self, qts: &[QToken], timeout: Option<Duration>) -> Result<(usize, demi_qresult_t), Fail> {
trace!("wait_any(): qts={:?}, timeout={:?}", qts, timeout);
