diff options
| author | Mica White <botahamec@outlook.com> | 2025-03-12 22:19:38 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2025-03-12 22:19:38 -0400 |
| commit | f347b3e7ca771f11a21d2f6e54c0d97796174d37 (patch) | |
| tree | 6776aa84a0fb91f5619f9669f083e0316f0526b9 /src/collection/ref.rs | |
| parent | 58abf5872023aca7ee6459fa3b2e067d57923ba5 (diff) | |
Add unwind handling for scoped locks
Diffstat (limited to 'src/collection/ref.rs')
| -rw-r--r-- | src/collection/ref.rs | 6 |
1 files changed, 5 insertions, 1 deletions
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<L: Lockable> 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<L: Debug> 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<LockGuard<L::Guard<'_>>, ThreadKey> { let guard = unsafe { + // safety: we have the thread key if !self.raw_try_write() { return Err(key); } |
