X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fsync%2Fnostd_sync.rs;h=0f92bd6caa3ad7c914b304db24d5fa69a8456b85;hb=cd5f09b8e34e838041a9dcdc512ddcf37a976634;hp=17307997d8176cc2b82a0d9559307971f3e2c252;hpb=0188861585db577723c4adedc43acd0f975944a5;p=rust-lightning diff --git a/lightning/src/sync/nostd_sync.rs b/lightning/src/sync/nostd_sync.rs index 17307997..0f92bd6c 100644 --- a/lightning/src/sync/nostd_sync.rs +++ b/lightning/src/sync/nostd_sync.rs @@ -1,30 +1,10 @@ pub use ::alloc::sync::Arc; use core::ops::{Deref, DerefMut}; -use core::time::Duration; use core::cell::{RefCell, Ref, RefMut}; use super::{LockTestExt, LockHeldState}; pub type LockResult = Result; -pub struct Condvar {} - -impl Condvar { - pub fn new() -> Condvar { - Condvar { } - } - - pub fn wait<'a, T>(&'a self, guard: MutexGuard<'a, T>) -> LockResult> { - Ok(guard) - } - - #[allow(unused)] - pub fn wait_timeout<'a, T>(&'a self, guard: MutexGuard<'a, T>, _dur: Duration) -> LockResult<(MutexGuard<'a, T>, ())> { - Ok((guard, ())) - } - - pub fn notify_all(&self) {} -} - pub struct Mutex { inner: RefCell } @@ -57,10 +37,6 @@ impl Mutex { Ok(MutexGuard { lock: self.inner.borrow_mut() }) } - pub fn try_lock<'a>(&'a self) -> LockResult> { - Ok(MutexGuard { lock: self.inner.borrow_mut() }) - } - pub fn into_inner(self) -> LockResult { Ok(self.inner.into_inner()) } @@ -69,7 +45,7 @@ impl Mutex { impl<'a, T: 'a> LockTestExt<'a> for Mutex { #[inline] fn held_by_thread(&self) -> LockHeldState { - if self.lock().is_err() { return LockHeldState::HeldByThread; } + if self.inner.try_borrow_mut().is_err() { return LockHeldState::HeldByThread; } else { return LockHeldState::NotHeldByThread; } } type ExclLock = MutexGuard<'a, T>; @@ -135,7 +111,7 @@ impl RwLock { impl<'a, T: 'a> LockTestExt<'a> for RwLock { #[inline] fn held_by_thread(&self) -> LockHeldState { - if self.write().is_err() { return LockHeldState::HeldByThread; } + if self.inner.try_borrow_mut().is_err() { return LockHeldState::HeldByThread; } else { return LockHeldState::NotHeldByThread; } } type ExclLock = RwLockWriteGuard<'a, T>;