From 660daaacdf862743b318ee85673900f91591d036 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 30 May 2023 18:11:47 +0000 Subject: [PATCH] Fix `held_by_thread` in `no-std` to return instead of panicing Our `no-std` locks simply panic if a lock cannot be taken as there should be no lock contention in a single-threaded environment. However, the `held_by_thread` debug methods were delegating to the lock methods which resulted in a panic when asserting that a lock *is* held by the current thread. Instead, they are updated here to call the relevant `RefCell` testing methods. --- lightning/src/sync/nostd_sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lightning/src/sync/nostd_sync.rs b/lightning/src/sync/nostd_sync.rs index 08d54a939..27cfb9b8f 100644 --- a/lightning/src/sync/nostd_sync.rs +++ b/lightning/src/sync/nostd_sync.rs @@ -49,7 +49,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>; @@ -115,7 +115,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>; -- 2.39.5