diff options
author | Fletcher Woodruff <fletcherw@chromium.org> | 2019-09-06 11:09:39 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-16 17:18:28 +0000 |
commit | 039b6727ba1cc31f322803392f0065dd3839a67d (patch) | |
tree | 2a0e5429c39b35bc5db7777a2860e6769369cde7 /sync | |
parent | 506105dc0dcfbbdec907f672e8d782b2f8604447 (diff) | |
download | crosvm-039b6727ba1cc31f322803392f0065dd3839a67d.tar crosvm-039b6727ba1cc31f322803392f0065dd3839a67d.tar.gz crosvm-039b6727ba1cc31f322803392f0065dd3839a67d.tar.bz2 crosvm-039b6727ba1cc31f322803392f0065dd3839a67d.tar.lz crosvm-039b6727ba1cc31f322803392f0065dd3839a67d.tar.xz crosvm-039b6727ba1cc31f322803392f0065dd3839a67d.tar.zst crosvm-039b6727ba1cc31f322803392f0065dd3839a67d.zip |
sync: add wait_timeout method to condvar wrapper
Adds a method wait_timeout to sync::Condvar which wraps std::sync::Condvar's wait_timeout. BUG=None TEST=cargo test Change-Id: I9888568b8bac779006080b505762016b6ca381e6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1789913 Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
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(); |