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/owned.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/collection/owned.rs') 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 Lockable for OwnedLockCollection { #[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 OwnedLockCollection { /// ``` pub fn try_lock(&self, key: ThreadKey) -> Result>, ThreadKey> { let guard = unsafe { + // safety: we've acquired the key if !self.raw_try_write() { return Err(key); } -- cgit v1.2.3