X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=lightning%2Fsrc%2Fsync%2Fnostd_sync.rs;h=e17aa6ab15faa5dc33b66dbc1b80ab79fd36cb18;hb=9c08fbd435b097c0aeec2843d8b4a6fdec06a8f0;hp=caf88a7cc04a8617a86e63988a7cc7a291fe96bc;hpb=e8b91a478bd2fd37fd726901271a8299847def3d;p=rust-lightning diff --git a/lightning/src/sync/nostd_sync.rs b/lightning/src/sync/nostd_sync.rs index caf88a7c..e17aa6ab 100644 --- a/lightning/src/sync/nostd_sync.rs +++ b/lightning/src/sync/nostd_sync.rs @@ -2,6 +2,7 @@ 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; @@ -61,6 +62,14 @@ impl Mutex { } } +impl LockTestExt for Mutex { + #[inline] + fn held_by_thread(&self) -> LockHeldState { + if self.lock().is_err() { return LockHeldState::HeldByThread; } + else { return LockHeldState::NotHeldByThread; } + } +} + pub struct RwLock { inner: RefCell } @@ -116,4 +125,12 @@ impl RwLock { } } +impl LockTestExt for RwLock { + #[inline] + fn held_by_thread(&self) -> LockHeldState { + if self.write().is_err() { return LockHeldState::HeldByThread; } + else { return LockHeldState::NotHeldByThread; } + } +} + pub type FairRwLock = RwLock;