From 92ff1a5988cdea5851930e286fd8a0abfd744471 Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 11 Mar 2024 22:09:33 -0400 Subject: Fix trait bounds --- src/mutex.rs | 3 ++- src/mutex/guard.rs | 10 +++++++++- src/mutex/mutex.rs | 2 +- src/rwlock.rs | 6 ++++-- src/rwlock/read_guard.rs | 10 +++++++++- src/rwlock/rwlock.rs | 2 +- src/rwlock/write_guard.rs | 10 +++++++++- 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/mutex.rs b/src/mutex.rs index b36854b..431eedc 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -49,5 +49,6 @@ pub struct MutexRef<'a, T: ?Sized + 'a, R: RawMutex>(&'a Mutex); pub struct MutexGuard<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable + 'key, R: RawMutex> { mutex: MutexRef<'a, T, R>, thread_key: Key, - _phantom: PhantomData<&'key ()>, + _phantom1: PhantomData<*const ()>, // implement !Send + _phantom2: PhantomData<&'key ()>, } diff --git a/src/mutex/guard.rs b/src/mutex/guard.rs index 9a309b4..5a2a2c1 100644 --- a/src/mutex/guard.rs +++ b/src/mutex/guard.rs @@ -61,7 +61,15 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawMutex> MutexGuard<'a, 'ke Self { mutex: MutexRef(mutex), thread_key, - _phantom: PhantomData, + _phantom1: PhantomData, + _phantom2: PhantomData, } } } + +unsafe impl<'a, T: ?Sized + 'a, R: RawMutex> Sync for MutexRef<'a, T, R> {} + +unsafe impl<'a, 'key: 'a, T: ?Sized + Sync, Key: Keyable + 'key, R: RawMutex> Sync + for MutexGuard<'_, 'key, T, Key, R> +{ +} diff --git a/src/mutex/mutex.rs b/src/mutex/mutex.rs index 83600b9..1976e57 100644 --- a/src/mutex/mutex.rs +++ b/src/mutex/mutex.rs @@ -227,4 +227,4 @@ impl Mutex { } unsafe impl Send for Mutex {} -unsafe impl Sync for Mutex {} +unsafe impl Sync for Mutex {} diff --git a/src/rwlock.rs b/src/rwlock.rs index fb40a71..f11b204 100644 --- a/src/rwlock.rs +++ b/src/rwlock.rs @@ -83,7 +83,8 @@ pub struct RwLockWriteRef<'a, T: ?Sized, R: RawRwLock>(&'a RwLock); pub struct RwLockReadGuard<'a, 'key, T: ?Sized, Key: Keyable + 'key, R: RawRwLock> { rwlock: RwLockReadRef<'a, T, R>, thread_key: Key, - _phantom: PhantomData<&'key ()>, + _phantom1: PhantomData<&'key ()>, + _phantom2: PhantomData<*const ()>, } /// RAII structure used to release the exclusive write access of a lock when @@ -96,5 +97,6 @@ pub struct RwLockReadGuard<'a, 'key, T: ?Sized, Key: Keyable + 'key, R: RawRwLoc pub struct RwLockWriteGuard<'a, 'key, T: ?Sized, Key: Keyable + 'key, R: RawRwLock> { rwlock: RwLockWriteRef<'a, T, R>, thread_key: Key, - _phantom: PhantomData<&'key ()>, + _phantom1: PhantomData<&'key ()>, + _phantom2: PhantomData<*const ()>, } diff --git a/src/rwlock/read_guard.rs b/src/rwlock/read_guard.rs index d8db9b9..074b0a9 100644 --- a/src/rwlock/read_guard.rs +++ b/src/rwlock/read_guard.rs @@ -46,7 +46,15 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock> Self { rwlock: RwLockReadRef(rwlock), thread_key, - _phantom: PhantomData, + _phantom1: PhantomData, + _phantom2: PhantomData, } } } + +unsafe impl<'a, T: ?Sized + 'a, R: RawRwLock> Sync for RwLockReadRef<'a, T, R> {} + +unsafe impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock> Sync + for RwLockReadGuard<'a, 'key, T, Key, R> +{ +} diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs index b1c7ff0..b1c4def 100644 --- a/src/rwlock/rwlock.rs +++ b/src/rwlock/rwlock.rs @@ -370,4 +370,4 @@ impl RwLock { } unsafe impl Send for RwLock {} -unsafe impl Sync for RwLock {} +unsafe impl Sync for RwLock {} diff --git a/src/rwlock/write_guard.rs b/src/rwlock/write_guard.rs index dd168bf..9350425 100644 --- a/src/rwlock/write_guard.rs +++ b/src/rwlock/write_guard.rs @@ -63,7 +63,15 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock> Self { rwlock: RwLockWriteRef(rwlock), thread_key, - _phantom: PhantomData, + _phantom1: PhantomData, + _phantom2: PhantomData, } } } + +unsafe impl<'a, T: ?Sized + 'a, R: RawRwLock> Sync for RwLockWriteRef<'a, T, R> {} + +unsafe impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock> Sync + for RwLockWriteGuard<'a, 'key, T, Key, R> +{ +} -- cgit v1.2.3