summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mutex.rs5
-rw-r--r--src/mutex/guard.rs6
-rw-r--r--src/mutex/mutex.rs6
-rw-r--r--src/rwlock.rs12
-rw-r--r--src/rwlock/read_guard.rs12
-rw-r--r--src/rwlock/rwlock.rs10
-rw-r--r--src/rwlock/write_guard.rs7
7 files changed, 29 insertions, 29 deletions
diff --git a/src/mutex.rs b/src/mutex.rs
index ed8d4a4..59e55a9 100644
--- a/src/mutex.rs
+++ b/src/mutex.rs
@@ -37,7 +37,10 @@ pub struct Mutex<T: ?Sized, R> {
}
/// A reference to a mutex that unlocks it when dropped
-pub struct MutexRef<'a, T: ?Sized + 'a, R: RawMutex>(&'a Mutex<T, R>);
+pub struct MutexRef<'a, T: ?Sized + 'a, R: RawMutex>(
+ &'a Mutex<T, R>,
+ PhantomData<(&'a mut T, R::GuardMarker)>,
+);
/// An RAII implementation of a “scoped lock” of a mutex. When this structure
/// is dropped (falls out of scope), the lock will be unlocked.
diff --git a/src/mutex/guard.rs b/src/mutex/guard.rs
index f57926d..69960cf 100644
--- a/src/mutex/guard.rs
+++ b/src/mutex/guard.rs
@@ -57,13 +57,13 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawMutex> MutexGuard<'a, 'ke
/// Create a guard to the given mutex. Undefined if multiple guards to the
/// same mutex exist at once.
#[must_use]
- pub(super) const unsafe fn new(mutex: &'a Mutex<T, R>, thread_key: Key) -> Self {
+ pub(super) unsafe fn new(mutex: &'a Mutex<T, R>, thread_key: Key) -> Self {
Self {
- mutex: MutexRef(mutex),
+ mutex: MutexRef(mutex, PhantomData),
thread_key,
_phantom2: PhantomData,
}
}
}
-unsafe impl<'a, T: ?Sized + Send + 'a, R: RawMutex + Sync + 'a> Sync for MutexRef<'a, T, R> {}
+unsafe impl<'a, T: ?Sized + Sync + 'a, R: RawMutex + Sync + 'a> Sync for MutexRef<'a, T, R> {}
diff --git a/src/mutex/mutex.rs b/src/mutex/mutex.rs
index 1976e57..917ab78 100644
--- a/src/mutex/mutex.rs
+++ b/src/mutex/mutex.rs
@@ -1,5 +1,5 @@
-use std::cell::UnsafeCell;
use std::fmt::Debug;
+use std::{cell::UnsafeCell, marker::PhantomData};
use lock_api::RawMutex;
@@ -144,7 +144,7 @@ impl<T: ?Sized, R: RawMutex> Mutex<T, R> {
pub(crate) unsafe fn lock_no_key(&self) -> MutexRef<'_, T, R> {
self.raw.lock();
- MutexRef(self)
+ MutexRef(self, PhantomData)
}
/// Attempts to lock the `Mutex` without blocking.
@@ -190,7 +190,7 @@ impl<T: ?Sized, R: RawMutex> Mutex<T, R> {
/// Lock without a [`ThreadKey`]. It is undefined behavior to do this without
/// owning the [`ThreadKey`].
pub(crate) unsafe fn try_lock_no_key(&self) -> Option<MutexRef<'_, T, R>> {
- self.raw.try_lock().then_some(MutexRef(self))
+ self.raw.try_lock().then_some(MutexRef(self, PhantomData))
}
/// Forcibly unlocks the `Lock`.
diff --git a/src/rwlock.rs b/src/rwlock.rs
index f11b204..df68fc5 100644
--- a/src/rwlock.rs
+++ b/src/rwlock.rs
@@ -67,10 +67,16 @@ pub struct ReadLock<'a, T: ?Sized, R>(&'a RwLock<T, R>);
pub struct WriteLock<'a, T: ?Sized, R>(&'a RwLock<T, R>);
/// RAII structure that unlocks the shared read access to a [`RwLock`]
-pub struct RwLockReadRef<'a, T: ?Sized, R: RawRwLock>(&'a RwLock<T, R>);
+pub struct RwLockReadRef<'a, T: ?Sized, R: RawRwLock>(
+ &'a RwLock<T, R>,
+ PhantomData<(&'a mut T, R::GuardMarker)>,
+);
/// RAII structure that unlocks the exclusive write access to a [`RwLock`]
-pub struct RwLockWriteRef<'a, T: ?Sized, R: RawRwLock>(&'a RwLock<T, R>);
+pub struct RwLockWriteRef<'a, T: ?Sized, R: RawRwLock>(
+ &'a RwLock<T, R>,
+ PhantomData<(&'a mut T, R::GuardMarker)>,
+);
/// RAII structure used to release the shared read access of a lock when
/// dropped.
@@ -84,7 +90,6 @@ pub struct RwLockReadGuard<'a, 'key, T: ?Sized, Key: Keyable + 'key, R: RawRwLoc
rwlock: RwLockReadRef<'a, T, R>,
thread_key: Key,
_phantom1: PhantomData<&'key ()>,
- _phantom2: PhantomData<*const ()>,
}
/// RAII structure used to release the exclusive write access of a lock when
@@ -98,5 +103,4 @@ pub struct RwLockWriteGuard<'a, 'key, T: ?Sized, Key: Keyable + 'key, R: RawRwLo
rwlock: RwLockWriteRef<'a, T, R>,
thread_key: Key,
_phantom1: PhantomData<&'key ()>,
- _phantom2: PhantomData<*const ()>,
}
diff --git a/src/rwlock/read_guard.rs b/src/rwlock/read_guard.rs
index 074b0a9..1fbbceb 100644
--- a/src/rwlock/read_guard.rs
+++ b/src/rwlock/read_guard.rs
@@ -42,19 +42,13 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock>
/// Create a guard to the given mutex. Undefined if multiple guards to the
/// same mutex exist at once.
#[must_use]
- pub(super) const unsafe fn new(rwlock: &'a RwLock<T, R>, thread_key: Key) -> Self {
+ pub(super) unsafe fn new(rwlock: &'a RwLock<T, R>, thread_key: Key) -> Self {
Self {
- rwlock: RwLockReadRef(rwlock),
+ rwlock: RwLockReadRef(rwlock, PhantomData),
thread_key,
_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>
-{
-}
+unsafe impl<'a, T: ?Sized + Sync + 'a, R: RawRwLock + Sync + 'a> Sync for RwLockReadRef<'a, T, R> {}
diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs
index b1c4def..dc5ab30 100644
--- a/src/rwlock/rwlock.rs
+++ b/src/rwlock/rwlock.rs
@@ -1,5 +1,5 @@
-use std::cell::UnsafeCell;
use std::fmt::Debug;
+use std::{cell::UnsafeCell, marker::PhantomData};
use lock_api::RawRwLock;
@@ -161,7 +161,7 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> {
self.raw.lock_shared();
// safety: the lock is locked first
- RwLockReadRef(self)
+ RwLockReadRef(self, PhantomData)
}
/// Attempts to acquire this `RwLock` with shared read access without
@@ -203,7 +203,7 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> {
pub(crate) unsafe fn try_read_no_key(&self) -> Option<RwLockReadRef<'_, T, R>> {
if self.raw.try_lock_shared() {
// safety: the lock is locked first
- Some(RwLockReadRef(self))
+ Some(RwLockReadRef(self, PhantomData))
} else {
None
}
@@ -252,7 +252,7 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> {
self.raw.lock_exclusive();
// safety: the lock is locked first
- RwLockWriteRef(self)
+ RwLockWriteRef(self, PhantomData)
}
/// Attempts to lock this `RwLock` with exclusive write access.
@@ -295,7 +295,7 @@ impl<T: ?Sized, R: RawRwLock> RwLock<T, R> {
pub(crate) unsafe fn try_write_no_key(&self) -> Option<RwLockWriteRef<'_, T, R>> {
if self.raw.try_lock_exclusive() {
// safety: the lock is locked first
- Some(RwLockWriteRef(self))
+ Some(RwLockWriteRef(self, PhantomData))
} else {
None
}
diff --git a/src/rwlock/write_guard.rs b/src/rwlock/write_guard.rs
index 09fb898..0121140 100644
--- a/src/rwlock/write_guard.rs
+++ b/src/rwlock/write_guard.rs
@@ -59,14 +59,13 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock>
/// Create a guard to the given mutex. Undefined if multiple guards to the
/// same mutex exist at once.
#[must_use]
- pub(super) const unsafe fn new(rwlock: &'a RwLock<T, R>, thread_key: Key) -> Self {
+ pub(super) unsafe fn new(rwlock: &'a RwLock<T, R>, thread_key: Key) -> Self {
Self {
- rwlock: RwLockWriteRef(rwlock),
+ rwlock: RwLockWriteRef(rwlock, PhantomData),
thread_key,
_phantom1: PhantomData,
- _phantom2: PhantomData,
}
}
}
-unsafe impl<'a, T: ?Sized + 'a, R: RawRwLock + Sync + 'a> Sync for RwLockWriteRef<'a, T, R> {}
+unsafe impl<'a, T: ?Sized + Sync + 'a, R: RawRwLock + Sync + 'a> Sync for RwLockWriteRef<'a, T, R> {}