From f347b3e7ca771f11a21d2f6e54c0d97796174d37 Mon Sep 17 00:00:00 2001 From: Mica White Date: Wed, 12 Mar 2025 22:19:38 -0400 Subject: Add unwind handling for scoped locks --- src/collection/ref.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/collection/ref.rs') diff --git a/src/collection/ref.rs b/src/collection/ref.rs index 5f96533..e71624d 100644 --- a/src/collection/ref.rs +++ b/src/collection/ref.rs @@ -71,7 +71,9 @@ unsafe impl Lockable for RefLockCollection<'_, L> { Self: 'a; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { - ptrs.push(self) + // Just like with BoxedLockCollection, we need to return all the individual + // locks to avoid duplicates + ptrs.extend_from_slice(&self.locks); } unsafe fn guard(&self) -> Self::Guard<'_> { @@ -115,6 +117,7 @@ impl Debug for RefLockCollection<'_, L> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct(stringify!(RefLockCollection)) .field("data", self.data) + // there's not much reason to show the sorting order .finish_non_exhaustive() } } @@ -314,6 +317,7 @@ impl<'a, L: Lockable> RefLockCollection<'a, L> { /// ``` pub fn try_lock(&self, key: ThreadKey) -> Result>, ThreadKey> { let guard = unsafe { + // safety: we have the thread key if !self.raw_try_write() { return Err(key); } -- cgit v1.2.3