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/boxed.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/collection/boxed.rs') diff --git a/src/collection/boxed.rs b/src/collection/boxed.rs index 1891119..0a30eac 100644 --- a/src/collection/boxed.rs +++ b/src/collection/boxed.rs @@ -23,7 +23,6 @@ unsafe impl RawLock for BoxedLockCollection { } unsafe fn raw_try_write(&self) -> bool { - println!("{}", self.locks().len()); utils::ordered_try_write(self.locks()) } @@ -60,7 +59,10 @@ unsafe impl Lockable for BoxedLockCollection { Self: 'a; fn get_ptrs<'a>(&'a self, ptrs: &mut Vec<&'a dyn RawLock>) { - ptrs.push(self); + // Doing it this way means that if a boxed collection is put inside a + // different collection, it will use the other method of locking. However, + // this prevents duplicate locks in a collection. + ptrs.extend_from_slice(&self.locks); } unsafe fn guard(&self) -> Self::Guard<'_> { @@ -170,6 +172,7 @@ impl Debug for BoxedLockCollection { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct(stringify!(BoxedLockCollection)) .field("data", &self.data) + // there's not much reason to show the sorted locks .finish_non_exhaustive() } } @@ -331,7 +334,7 @@ impl BoxedLockCollection { // cast to *const () because fat pointers can't be converted to usize locks.sort_by_key(|lock| (&raw const **lock).cast::<()>() as usize); - // safety we're just changing the lifetimes + // safety: we're just changing the lifetimes let locks: Vec<&'static dyn RawLock> = std::mem::transmute(locks); let data = &raw const *data; Self { data, locks } -- cgit v1.2.3