From 7bd236853ef5ae705328c8fdc492cf60fc6887c1 Mon Sep 17 00:00:00 2001 From: Mica White Date: Wed, 13 Mar 2024 22:44:46 -0400 Subject: Lockable overhaul --- src/collection.rs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/collection.rs') diff --git a/src/collection.rs b/src/collection.rs index c6cbe2d..1c276a6 100644 --- a/src/collection.rs +++ b/src/collection.rs @@ -1,23 +1,41 @@ -use std::marker::PhantomData; +use std::marker::{PhantomData, PhantomPinned}; +use std::ptr::NonNull; -use crate::{key::Keyable, lockable::Lockable}; +use crate::{ + key::Keyable, + lockable::{Lock, Lockable}, +}; mod collection; mod guard; +pub struct OwnedLockCollection { + data: L, +} + /// A type which can be locked. /// /// This could be a tuple of [`Lockable`] types, an array, or a `Vec`. But it -/// can be safely locked without causing a deadlock. To do this, it is very -/// important that no duplicate locks are included within. -#[derive(Debug, Clone, Copy)] -pub struct LockCollection { +/// can be safely locked without causing a deadlock. +pub struct RefLockCollection<'a, L> { + locks: Vec<&'a dyn Lock>, + data: &'a L, +} + +pub struct BoxedLockCollection(RefLockCollection<'static, L>); + +pub struct PinnedLockCollection { + _unpin: PhantomPinned, data: L, + locks: Vec>, } +unsafe impl Send for PinnedLockCollection {} +unsafe impl Sync for PinnedLockCollection {} + /// A RAII guard for a generic [`Lockable`] type. pub struct LockGuard<'a, 'key: 'a, L: Lockable<'a>, Key: Keyable + 'key> { - guard: L::Output, + guard: L::Guard, key: Key, _phantom: PhantomData<&'key ()>, } -- cgit v1.2.3