Include Refund context in blinded payment paths
[rust-lightning] / lightning / src / sync / nostd_sync.rs
index e17aa6ab15faa5dc33b66dbc1b80ab79fd36cb18..0f92bd6caa3ad7c914b304db24d5fa69a8456b85 100644 (file)
@@ -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<Guard> = Result<Guard, ()>;
 
-pub struct Condvar {}
-
-impl Condvar {
-       pub fn new() -> Condvar {
-               Condvar { }
-       }
-
-       pub fn wait<'a, T>(&'a self, guard: MutexGuard<'a, T>) -> LockResult<MutexGuard<'a, T>> {
-               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<T: ?Sized> {
        inner: RefCell<T>
 }
@@ -57,17 +37,20 @@ impl<T> Mutex<T> {
                Ok(MutexGuard { lock: self.inner.borrow_mut() })
        }
 
-       pub fn try_lock<'a>(&'a self) -> LockResult<MutexGuard<'a, T>> {
-               Ok(MutexGuard { lock: self.inner.borrow_mut() })
+       pub fn into_inner(self) -> LockResult<T> {
+               Ok(self.inner.into_inner())
        }
 }
 
-impl<T> LockTestExt for Mutex<T> {
+impl<'a, T: 'a> LockTestExt<'a> for Mutex<T> {
        #[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>;
+       #[inline]
+       fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard<T> { self.lock().unwrap() }
 }
 
 pub struct RwLock<T: ?Sized> {
@@ -125,12 +108,15 @@ impl<T> RwLock<T> {
        }
 }
 
-impl<T> LockTestExt for RwLock<T> {
+impl<'a, T: 'a> LockTestExt<'a> for RwLock<T> {
        #[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>;
+       #[inline]
+       fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard<T> { self.write().unwrap() }
 }
 
 pub type FairRwLock<T> = RwLock<T>;