diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:12:43 +0000 |
commit | cf94bdc0742c13e2a0cac864c478b8626b266e1b (patch) | |
tree | 044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /vendor/lock_api/src/mutex.rs | |
parent | Adding debian version 1.65.0+dfsg1-2. (diff) | |
download | rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.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.rs | 29 |
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. |