summaryrefslogtreecommitdiff
path: root/src/mutex
diff options
context:
space:
mode:
Diffstat (limited to 'src/mutex')
-rw-r--r--src/mutex/guard.rs6
-rw-r--r--src/mutex/mutex.rs26
2 files changed, 23 insertions, 9 deletions
diff --git a/src/mutex/guard.rs b/src/mutex/guard.rs
index c7f25e4..38ea125 100644
--- a/src/mutex/guard.rs
+++ b/src/mutex/guard.rs
@@ -35,6 +35,12 @@ impl<'a, T: ?Sized + 'a, R: RawMutex> DerefMut for MutexRef<'a, T, R> {
}
}
+impl<'a, T: ?Sized + 'a, R: RawMutex> MutexRef<'a, T, R> {
+ pub unsafe fn new(mutex: &'a Mutex<T, R>) -> Self {
+ Self(mutex, PhantomData)
+ }
+}
+
impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawMutex> Deref
for MutexGuard<'a, 'key, T, Key, R>
{
diff --git a/src/mutex/mutex.rs b/src/mutex/mutex.rs
index 917ab78..3b8c221 100644
--- a/src/mutex/mutex.rs
+++ b/src/mutex/mutex.rs
@@ -24,6 +24,23 @@ impl<T, R: RawMutex> Mutex<T, R> {
data: UnsafeCell::new(data),
}
}
+
+ /// Returns the raw underlying mutex.
+ ///
+ /// Note that you will most likely need to import the [`RawMutex`] trait
+ /// from `lock_api` to be able to call functions on the raw mutex.
+ ///
+ /// # Safety
+ ///
+ /// This method is unsafe because it allows unlocking a mutex while still
+ /// holding a reference to a [`MutexGuard`], and locking a mutex without
+ /// holding the [`ThreadKey`].
+ ///
+ /// [`ThreadKey`]: `crate::ThreadKey`
+ #[must_use]
+ pub const unsafe fn raw(&self) -> &R {
+ &self.raw
+ }
}
impl<T: ?Sized + Default, R: RawMutex> Default for Mutex<T, R> {
@@ -138,15 +155,6 @@ impl<T: ?Sized, R: RawMutex> Mutex<T, R> {
}
}
- /// Lock without a [`ThreadKey`]. You must exclusively own the
- /// [`ThreadKey`] as long as the [`MutexRef`] is alive. This may cause
- /// deadlock if called multiple times without unlocking first.
- pub(crate) unsafe fn lock_no_key(&self) -> MutexRef<'_, T, R> {
- self.raw.lock();
-
- MutexRef(self, PhantomData)
- }
-
/// Attempts to lock the `Mutex` without blocking.
///
/// # Errors