Skip to content

Commit 660daaa

Browse files
committed
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.
1 parent 9e542ec commit 660daaa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lightning/src/sync/nostd_sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<T> Mutex<T> {
4949
impl<'a, T: 'a> LockTestExt<'a> for Mutex<T> {
5050
#[inline]
5151
fn held_by_thread(&self) -> LockHeldState {
52-
if self.lock().is_err() { return LockHeldState::HeldByThread; }
52+
if self.inner.try_borrow_mut().is_err() { return LockHeldState::HeldByThread; }
5353
else { return LockHeldState::NotHeldByThread; }
5454
}
5555
type ExclLock = MutexGuard<'a, T>;
@@ -115,7 +115,7 @@ impl<T> RwLock<T> {
115115
impl<'a, T: 'a> LockTestExt<'a> for RwLock<T> {
116116
#[inline]
117117
fn held_by_thread(&self) -> LockHeldState {
118-
if self.write().is_err() { return LockHeldState::HeldByThread; }
118+
if self.inner.try_borrow_mut().is_err() { return LockHeldState::HeldByThread; }
119119
else { return LockHeldState::NotHeldByThread; }
120120
}
121121
type ExclLock = RwLockWriteGuard<'a, T>;

0 commit comments

Comments
 (0)