diff options
Diffstat (limited to 'sync')
-rw-r--r-- | sync/src/condvar.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/sync/src/condvar.rs b/sync/src/condvar.rs index 4a6e80d..6d5d2b2 100644 --- a/sync/src/condvar.rs +++ b/sync/src/condvar.rs @@ -3,7 +3,8 @@ // found in the LICENSE file. use std::fmt::{self, Debug}; -use std::sync::{Condvar as StdCondvar, MutexGuard}; +use std::sync::{Condvar as StdCondvar, MutexGuard, WaitTimeoutResult}; +use std::time::Duration; /// A Condition Variable. #[derive(Default)] @@ -27,6 +28,19 @@ impl Condvar { } } + /// Waits on a condvar, blocking the current thread until it is notified + /// or the specified duration has elapsed. + pub fn wait_timeout<'a, T>( + &self, + guard: MutexGuard<'a, T>, + dur: Duration, + ) -> (MutexGuard<'a, T>, WaitTimeoutResult) { + match self.std.wait_timeout(guard, dur) { + Ok(result) => result, + Err(_) => panic!("condvar is poisoned"), + } + } + /// Notifies one thread blocked by this condvar. pub fn notify_one(&self) { self.std.notify_one(); |