Skip to content

Commit 141cf3d

Browse files
committed
Add CondVar::wait_{timeout_,}while to debug_sync
These are useful, but we previously couldn't use them due to our MSRV. Now that we can, we should use them, so we expose them via our normal debug_sync wrappers.
1 parent 2fab887 commit 141cf3d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lightning/src/sync/debug_sync.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use std::sync::RwLockReadGuard as StdRwLockReadGuard;
1212
use std::sync::RwLockWriteGuard as StdRwLockWriteGuard;
1313
use std::sync::Condvar as StdCondvar;
1414

15+
pub use std::sync::WaitTimeoutResult;
16+
1517
use crate::prelude::HashMap;
1618

1719
use super::{LockTestExt, LockHeldState};
@@ -40,12 +42,27 @@ impl Condvar {
4042
self.inner.wait(guard.into_inner()).map(|lock| MutexGuard { mutex, lock }).map_err(|_| ())
4143
}
4244

45+
pub fn wait_while<'a, T, F: FnMut(&mut T) -> bool>(&'a self, guard: MutexGuard<'a, T>, condition: F)
46+
-> LockResult<MutexGuard<'a, T>> {
47+
let mutex: &'a Mutex<T> = guard.mutex;
48+
self.inner.wait_while(guard.into_inner(), condition).map(|lock| MutexGuard { mutex, lock })
49+
.map_err(|_| ())
50+
}
51+
4352
#[allow(unused)]
4453
pub fn wait_timeout<'a, T>(&'a self, guard: MutexGuard<'a, T>, dur: Duration) -> LockResult<(MutexGuard<'a, T>, ())> {
4554
let mutex = guard.mutex;
4655
self.inner.wait_timeout(guard.into_inner(), dur).map(|(lock, _)| (MutexGuard { mutex, lock }, ())).map_err(|_| ())
4756
}
4857

58+
#[allow(unused)]
59+
pub fn wait_timeout_while<'a, T, F: FnMut(&mut T) -> bool>(&'a self, guard: MutexGuard<'a, T>, dur: Duration, condition: F)
60+
-> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)> {
61+
let mutex = guard.mutex;
62+
self.inner.wait_timeout_while(guard.into_inner(), dur, condition).map_err(|_| ())
63+
.map(|(lock, e)| (MutexGuard { mutex, lock }, e))
64+
}
65+
4966
pub fn notify_all(&self) { self.inner.notify_all(); }
5067
}
5168

0 commit comments

Comments
 (0)