diff options
| author | Botahamec <botahamec@outlook.com> | 2024-05-29 13:36:47 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2024-05-29 13:36:47 -0400 |
| commit | 2c26dd547323d39efb7aa6bf9fdf081b8953c223 (patch) | |
| tree | 5d46e189bb6f6efbdc88521cf3735423d5415cb4 /src/collection.rs | |
| parent | 35111cad16ad5202a511f85fce90196fad6f7707 (diff) | |
Fix UB with UnsafeCell
Diffstat (limited to 'src/collection.rs')
| -rw-r--r-- | src/collection.rs | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/src/collection.rs b/src/collection.rs index 8227362..c1c7697 100644 --- a/src/collection.rs +++ b/src/collection.rs @@ -1,5 +1,5 @@ +use std::cell::UnsafeCell; use std::marker::PhantomData; -use std::ptr::NonNull; use crate::{key::Keyable, lockable::RawLock}; @@ -86,17 +86,8 @@ pub struct RefLockCollection<'a, L> { // This type caches the sorting order of the locks and the fact that it doesn't // contain any duplicates. pub struct BoxedLockCollection<L> { - // Box isn't used directly because it requires that the data not be - // aliased. To resolve this, we'll have to ensure that only one of the - // following is true at any given time: - // - // 1. We have a mutable reference to the data - // 2. We have immutable references to the data and locks - // - // This is enforced by having #1 be true for a mutable or owned reference - // to the value, and #2 is true for an immutable reference. - data: NonNull<L>, - locks: Vec<NonNull<dyn RawLock>>, + data: *const UnsafeCell<L>, + locks: Vec<&'static dyn RawLock>, } /// Locks a collection of locks using a retrying algorithm. |
