diff options
Diffstat (limited to 'vendor/lock_api/src')
-rw-r--r-- | vendor/lock_api/src/mutex.rs | 29 | ||||
-rw-r--r-- | vendor/lock_api/src/remutex.rs | 8 | ||||
-rw-r--r-- | vendor/lock_api/src/rwlock.rs | 10 |
3 files changed, 35 insertions, 12 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. 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<U: ?Sized, F>( @@ -654,10 +654,10 @@ impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> ReentrantMutexGu f: F, ) -> Result<MappedReentrantMutexGuard<'a, R, G, U>, 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<U: ?Sized, F>( 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<U: ?Sized, F>(s: Self, f: F) -> Result<MappedRwLockReadGuard<'a, R, U>, 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<U: ?Sized, F>(s: Self, f: F) -> Result<MappedRwLockWriteGuard<'a, R, U>, 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<U: ?Sized, F>(s: Self, f: F) -> Result<MappedRwLockReadGuard<'a, R, U>, 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<U: ?Sized, F>(s: Self, f: F) -> Result<MappedRwLockWriteGuard<'a, R, U>, Self> |