From 20431706a863f92cb37dc512fef6e48d192aaf2c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:38 +0200 Subject: Merging upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/lock_api/src/mutex.rs | 29 ++++++++++++++++++++++++++--- vendor/lock_api/src/remutex.rs | 8 ++++---- vendor/lock_api/src/rwlock.rs | 10 +++++----- 3 files changed, 35 insertions(+), 12 deletions(-) (limited to 'vendor/lock_api/src') 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 { mutex: Arc>, - marker: PhantomData, + marker: PhantomData<*const ()>, +} + +#[cfg(feature = "arc_lock")] +unsafe impl Send for ArcMutexGuard where + R::GuardMarker: Send +{ +} +#[cfg(feature = "arc_lock")] +unsafe impl Sync for ArcMutexGuard where + R::GuardMarker: Sync +{ } #[cfg(feature = "arc_lock")] impl ArcMutexGuard { /// Returns a reference to the `Mutex` this is guarding, contained in its `Arc`. #[inline] - pub fn mutex(&self) -> &Arc> { - &self.mutex + pub fn mutex(s: &Self) -> &Arc> { + &s.mutex + } + + /// Unlocks the mutex and returns the `Arc` that was held by the [`ArcMutexGuard`]. + #[inline] + pub fn into_arc(s: Self) -> Arc> { + // 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. diff --git a/vendor/lock_api/src/remutex.rs b/vendor/lock_api/src/remutex.rs index fa0e934d1..3e2010f2b 100644 --- a/vendor/lock_api/src/remutex.rs +++ b/vendor/lock_api/src/remutex.rs @@ -646,7 +646,7 @@ impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGu /// in already locked the mutex. /// /// This is an associated function that needs to be - /// used as `ReentrantMutexGuard::map(...)`. A method would interfere with methods of + /// used as `ReentrantMutexGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map( @@ -654,10 +654,10 @@ impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGu f: F, ) -> Result, Self> where - F: FnOnce(&mut T) -> Option<&mut U>, + F: FnOnce(&T) -> Option<&U>, { let raw = &s.remutex.raw; - let data = match f(unsafe { &mut *s.remutex.data.get() }) { + let data = match f(unsafe { &*s.remutex.data.get() }) { Some(data) => data, None => return Err(s), }; @@ -942,7 +942,7 @@ impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> /// in already locked the mutex. /// /// This is an associated function that needs to be - /// used as `MappedReentrantMutexGuard::map(...)`. A method would interfere with methods of + /// used as `MappedReentrantMutexGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map( diff --git a/vendor/lock_api/src/rwlock.rs b/vendor/lock_api/src/rwlock.rs index e947f1ec0..c972fb6c6 100644 --- a/vendor/lock_api/src/rwlock.rs +++ b/vendor/lock_api/src/rwlock.rs @@ -1218,13 +1218,13 @@ impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> RwLockReadGuard<'a, R, T> { } /// Attempts to make a new `MappedRwLockReadGuard` for a component of the - /// locked data. The original guard is return if the closure returns `None`. + /// locked data. Returns the original guard if the closure returns `None`. /// /// This operation cannot fail as the `RwLockReadGuard` passed /// in already locked the data. /// /// This is an associated function that needs to be - /// used as `RwLockReadGuard::map(...)`. A method would interfere with methods of + /// used as `RwLockReadGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map(s: Self, f: F) -> Result, Self> @@ -1512,7 +1512,7 @@ impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> RwLockWriteGuard<'a, R, T> { /// in already locked the data. /// /// This is an associated function that needs to be - /// used as `RwLockWriteGuard::map(...)`. A method would interfere with methods of + /// used as `RwLockWriteGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map(s: Self, f: F) -> Result, Self> @@ -2374,7 +2374,7 @@ impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> MappedRwLockReadGuard<'a, R, T> { /// in already locked the data. /// /// This is an associated function that needs to be - /// used as `MappedRwLockReadGuard::map(...)`. A method would interfere with methods of + /// used as `MappedRwLockReadGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map(s: Self, f: F) -> Result, Self> @@ -2512,7 +2512,7 @@ impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> MappedRwLockWriteGuard<'a, R, T> { /// in already locked the data. /// /// This is an associated function that needs to be - /// used as `MappedRwLockWriteGuard::map(...)`. A method would interfere with methods of + /// used as `MappedRwLockWriteGuard::try_map(...)`. A method would interfere with methods of /// the same name on the contents of the locked data. #[inline] pub fn try_map(s: Self, f: F) -> Result, Self> -- cgit v1.2.3