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/owned.rs | |
| parent | 58abf5872023aca7ee6459fa3b2e067d57923ba5 (diff) | |
Add unwind handling for scoped locks
Diffstat (limited to 'src/collection/owned.rs')
| -rw-r--r-- | src/collection/owned.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/collection/owned.rs b/src/collection/owned.rs index 68170d1..866d778 100644 --- a/src/collection/owned.rs +++ b/src/collection/owned.rs @@ -63,6 +63,9 @@ unsafe impl<L: Lockable> Lockable for OwnedLockCollection<L> { #[mutants::skip] // It's hard to test lkocks in an OwnedLockCollection, because they're owned #[cfg(not(tarpaulin_include))] fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { + // It's ok to use self here, because the values in the collection already + // cannot be referenced anywhere else. It's necessary to use self as the lock + // because otherwise we will be handing out shared references to the child ptrs.push(self) } @@ -263,6 +266,7 @@ impl<L: OwnedLockable> OwnedLockCollection<L> { /// ``` pub fn try_lock(&self, key: ThreadKey) -> Result<LockGuard<L::Guard<'_>>, ThreadKey> { let guard = unsafe { + // safety: we've acquired the key if !self.raw_try_write() { return Err(key); } |
