summaryrefslogtreecommitdiffstats
path: root/vendor/lock_api/src/mutex.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:11:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:13:23 +0000
commit20431706a863f92cb37dc512fef6e48d192aaf2c (patch)
tree2867f13f5fd5437ba628c67d7f87309ccadcd286 /vendor/lock_api/src/mutex.rs
parentReleasing progress-linux version 1.65.0+dfsg1-2~progress7.99u1. (diff)
downloadrustc-20431706a863f92cb37dc512fef6e48d192aaf2c.tar.xz
rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.zip
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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.