summaryrefslogtreecommitdiffstats
path: root/vendor/lock_api/src/mutex.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/lock_api/src/mutex.rs')
-rw-r--r--vendor/lock_api/src/mutex.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/vendor/lock_api/src/mutex.rs b/vendor/lock_api/src/mutex.rs
index 4e1b879e5..c97e5430b 100644
--- a/vendor/lock_api/src/mutex.rs
+++ b/vendor/lock_api/src/mutex.rs
@@ -681,15 +681,38 @@ unsafe impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> StableAddress for MutexGuard<'
#[must_use = "if unused the Mutex will immediately unlock"]
pub struct ArcMutexGuard<R: RawMutex, T: ?Sized> {
mutex: Arc<Mutex<R, T>>,
- marker: PhantomData<R::GuardMarker>,
+ marker: PhantomData<*const ()>,
+}
+
+#[cfg(feature = "arc_lock")]
+unsafe impl<R: RawMutex + Send + Sync, T: Send + ?Sized> Send for ArcMutexGuard<R, T> where
+ R::GuardMarker: Send
+{
+}
+#[cfg(feature = "arc_lock")]
+unsafe impl<R: RawMutex + Sync, T: Sync + ?Sized> Sync for ArcMutexGuard<R, T> where
+ R::GuardMarker: Sync
+{
}
#[cfg(feature = "arc_lock")]
impl<R: RawMutex, T: ?Sized> ArcMutexGuard<R, T> {
/// Returns a reference to the `Mutex` this is guarding, contained in its `Arc`.
#[inline]
- pub fn mutex(&self) -> &Arc<Mutex<R, T>> {
- &self.mutex
+ pub fn mutex(s: &Self) -> &Arc<Mutex<R, T>> {
+ &s.mutex
+ }
+
+ /// Unlocks the mutex and returns the `Arc` that was held by the [`ArcMutexGuard`].
+ #[inline]
+ pub fn into_arc(s: Self) -> Arc<Mutex<R, T>> {
+ // Safety: Skip our Drop impl and manually unlock the mutex.
+ let arc = unsafe { ptr::read(&s.mutex) };
+ mem::forget(s);
+ unsafe {
+ arc.raw.unlock();
+ }
+ arc
}
/// Temporarily unlocks the mutex to execute the given function.