summaryrefslogtreecommitdiff
path: root/src/collection/boxed.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2025-03-12 22:19:38 -0400
committerMica White <botahamec@outlook.com>2025-03-12 22:19:38 -0400
commitf347b3e7ca771f11a21d2f6e54c0d97796174d37 (patch)
tree6776aa84a0fb91f5619f9669f083e0316f0526b9 /src/collection/boxed.rs
parent58abf5872023aca7ee6459fa3b2e067d57923ba5 (diff)
Add unwind handling for scoped locks
Diffstat (limited to 'src/collection/boxed.rs')
-rw-r--r--src/collection/boxed.rs9
1 files changed, 6 insertions, 3 deletions
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<L: Lockable> RawLock for BoxedLockCollection<L> {
}
unsafe fn raw_try_write(&self) -> bool {
- println!("{}", self.locks().len());
utils::ordered_try_write(self.locks())
}
@@ -60,7 +59,10 @@ unsafe impl<L: Lockable> Lockable for BoxedLockCollection<L> {
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<L: Debug> Debug for BoxedLockCollection<L> {
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<L: Lockable> BoxedLockCollection<L> {
// 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 }