X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Fsync%2Fnostd_sync.rs;fp=lightning%2Fsrc%2Fsync%2Fnostd_sync.rs;h=ee3e375028eba44bbb0ac723b0eb520c398be227;hb=a1b5a1bba38e0a4ab08603adbcf9e54f27e86f19;hp=17307997d8176cc2b82a0d9559307971f3e2c252;hpb=2fab8873f939242bcde16ee4b9a107d288e8c535;p=rust-lightning diff --git a/lightning/src/sync/nostd_sync.rs b/lightning/src/sync/nostd_sync.rs index 17307997..ee3e3750 100644 --- a/lightning/src/sync/nostd_sync.rs +++ b/lightning/src/sync/nostd_sync.rs @@ -8,6 +8,11 @@ pub type LockResult = Result; pub struct Condvar {} +pub struct WaitTimeoutResult(bool); +impl WaitTimeoutResult { + pub fn timed_out(&self) -> bool { self.0 } +} + impl Condvar { pub fn new() -> Condvar { Condvar { } @@ -22,6 +27,22 @@ impl 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> { + 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) {} }