use std::sync::RwLockWriteGuard as StdRwLockWriteGuard;
use std::sync::Condvar as StdCondvar;
+pub use std::sync::WaitTimeoutResult;
+
use crate::prelude::HashMap;
use super::{LockTestExt, LockHeldState};
self.inner.wait(guard.into_inner()).map(|lock| MutexGuard { mutex, lock }).map_err(|_| ())
}
+ pub fn wait_while<'a, T, F: FnMut(&mut T) -> bool>(&'a self, guard: MutexGuard<'a, T>, condition: F)
+ -> LockResult<MutexGuard<'a, T>> {
+ let mutex: &'a Mutex<T> = guard.mutex;
+ self.inner.wait_while(guard.into_inner(), condition).map(|lock| MutexGuard { mutex, lock })
+ .map_err(|_| ())
+ }
+
#[allow(unused)]
pub fn wait_timeout<'a, T>(&'a self, guard: MutexGuard<'a, T>, dur: Duration) -> LockResult<(MutexGuard<'a, T>, ())> {
let mutex = guard.mutex;
self.inner.wait_timeout(guard.into_inner(), dur).map(|(lock, _)| (MutexGuard { mutex, lock }, ())).map_err(|_| ())
}
+ #[allow(unused)]
+ pub fn wait_timeout_while<'a, T, F: FnMut(&mut T) -> bool>(&'a self, guard: MutexGuard<'a, T>, dur: Duration, condition: F)
+ -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)> {
+ let mutex = guard.mutex;
+ self.inner.wait_timeout_while(guard.into_inner(), dur, condition).map_err(|_| ())
+ .map(|(lock, e)| (MutexGuard { mutex, lock }, e))
+ }
+
pub fn notify_all(&self) { self.inner.notify_all(); }
}
pub struct Condvar {}
+pub struct WaitTimeoutResult(bool);
+impl WaitTimeoutResult {
+ pub fn timed_out(&self) -> bool { self.0 }
+}
+
impl Condvar {
pub fn new() -> Condvar {
Condvar { }
Ok((guard, ()))
}
+ pub fn wait_while<'a, T, F: FnMut(&mut T) -> bool>(&'a self, mut guard: MutexGuard<'a, T>, mut condition: F)
+ -> LockResult<MutexGuard<'a, T>> {
+ assert!(!condition(&mut *guard));
+ Ok(guard)
+ }
+
+ #[allow(unused)]
+ pub fn wait_timeout_while<'a, T, F: FnMut(&mut T) -> bool>(&'a self, mut guard: MutexGuard<'a, T>, dur: Duration, mut condition: F)
+ -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)> {
+ if condition(&mut *guard) {
+ Ok((guard, WaitTimeoutResult(true)))
+ } else {
+ Ok((guard, WaitTimeoutResult(false)))
+ }
+ }
+
pub fn notify_all(&self) {}
}