Skip to content

Commit

Permalink
whoops
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed Jul 30, 2021
1 parent e687378 commit 8b0eb2f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
11 changes: 6 additions & 5 deletions lock_api/src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,10 @@ impl<'a, R: RawMutex + 'a, T: fmt::Display + ?Sized + 'a> fmt::Display for Mutex
#[cfg(feature = "owning_ref")]
unsafe impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> StableAddress for MutexGuard<'a, R, T> {}

/// An RAII mutex guard returned by the `Arc` locking operations on `Mutex`. This is similar to the `MutexGuard`
/// struct, except instead of using a reference to unlock the `Mutex` it uses an `Arc<Mutex>`. This has several
/// advantages, most notably that it has an `'static` lifetime.
/// An RAII mutex guard returned by the `Arc` locking operations on `Mutex`.
///
/// This is similar to the `MutexGuard` struct, except instead of using a reference to unlock the `Mutex` it
/// uses an `Arc<Mutex>`. This has several advantages, most notably that it has an `'static` lifetime.
#[cfg(feature = "arc_lock")]
#[must_use = "if unused the Mutex will immediately unlock"]
pub struct ArcMutexGuard<R: RawMutex, T: ?Sized> {
Expand Down Expand Up @@ -711,8 +712,8 @@ impl<R: RawMutexFair, T: ?Sized> ArcMutexGuard<R, T> {
}

// SAFETY: make sure the Arc gets it reference decremented
let s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&s.rwlock) };
let mut s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&mut s.mutex) };
}

/// Temporarily unlocks the mutex to execute the given function.
Expand Down
12 changes: 7 additions & 5 deletions lock_api/src/remutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,11 @@ unsafe impl<'a, R: RawMutex + 'a, G: GetThreadId + 'a, T: ?Sized + 'a> StableAdd
{
}

/// An RAII mutex guard returned by the `Arc` locking operations on `ReentrantMutex`. This is similar to the
/// `ReentrantMutexGuard` struct, except instead of using a reference to unlock the `Mutex` it uses an
/// `Arc<ReentrantMutex>`. This has several advantages, most notably that it has an `'static` lifetime.
/// An RAII mutex guard returned by the `Arc` locking operations on `ReentrantMutex`.
///
/// This is similar to the `ReentrantMutexGuard` struct, except instead of using a reference to unlock the
/// `Mutex` it uses an `Arc<ReentrantMutex>`. This has several advantages, most notably that it has an `'static`
/// lifetime.
#[cfg(feature = "arc_lock")]
#[must_use = "if unused the ReentrantMutex will immediately unlock"]
pub struct ArcReentrantMutexGuard<R: RawMutex, G: GetThreadId, T: ?Sized> {
Expand Down Expand Up @@ -833,8 +835,8 @@ impl<R: RawMutexFair, G: GetThreadId, T: ?Sized>
}

// SAFETY: ensure that the Arc's refcount is decremented
let s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&s.rwlock) };
let mut s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&mut s.remutex) };
}

/// Temporarily unlocks the mutex to execute the given function.
Expand Down
38 changes: 20 additions & 18 deletions lock_api/src/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ impl<R: RawRwLockRecursive, T: ?Sized> RwLock<R, T> {
#[cfg(feature = "arc_lock")]
#[inline]
pub fn read_arc_recursive(self: &Arc<Self>) -> ArcRwLockReadGuard<R, T> {
this.raw.lock_shared_recursive();
self.raw.lock_shared_recursive();
// SAFETY: locking guarantee is upheld
unsafe { self.read_guard_arc() }
}
Expand Down Expand Up @@ -1085,7 +1085,7 @@ impl<R: RawRwLockUpgradeTimed, T: ?Sized> RwLock<R, T> {
) -> Option<ArcRwLockUpgradableReadGuard<R, T>> {
if self.raw.try_lock_upgradable_for(timeout) {
// SAFETY: locking guarantee is upheld
Some(unsafe { self.upgradable_guard_arc(this) })
Some(unsafe { self.upgradable_guard_arc() })
} else {
None
}
Expand All @@ -1098,7 +1098,7 @@ impl<R: RawRwLockUpgradeTimed, T: ?Sized> RwLock<R, T> {
#[cfg(feature = "arc_lock")]
#[inline]
pub fn try_upgradable_read_arc_until(
this: &Arc<Self>,
self: &Arc<Self>,
timeout: R::Instant,
) -> Option<ArcRwLockUpgradableReadGuard<R, T>> {
if self.raw.try_lock_upgradable_until(timeout) {
Expand Down Expand Up @@ -1318,9 +1318,10 @@ impl<'a, R: RawRwLock + 'a, T: fmt::Display + ?Sized + 'a> fmt::Display
#[cfg(feature = "owning_ref")]
unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> StableAddress for RwLockReadGuard<'a, R, T> {}

/// An RAII rwlock guard returned by the `Arc` locking operations on `RwLock`. This is similar to the
/// `RwLockReadGuard` struct, except instead of using a reference to unlock the `RwLock` it uses an
/// `Arc<RwLock>`. This has several advantages, most notably that it has an `'static` lifetime.
/// An RAII rwlock guard returned by the `Arc` locking operations on `RwLock`.
///
/// This is similar to the `RwLockReadGuard` struct, except instead of using a reference to unlock the `RwLock`
/// it uses an `Arc<RwLock>`. This has several advantages, most notably that it has an `'static` lifetime.
#[cfg(feature = "arc_lock")]
#[must_use = "if unused the RwLock will immediately unlock"]
pub struct ArcRwLockReadGuard<R: RawRwLock, T: ?Sized> {
Expand Down Expand Up @@ -1365,8 +1366,8 @@ impl<R: RawRwLockFair, T: ?Sized> ArcRwLockReadGuard<R, T> {
}

// SAFETY: ensure the Arc has its refcount decremented
let s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&s.rwlock) };
let mut s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&mut s.rwlock) };
}

/// Temporarily unlocks the `RwLock` to execute the given function.
Expand Down Expand Up @@ -1654,9 +1655,9 @@ impl<'a, R: RawRwLock + 'a, T: fmt::Display + ?Sized + 'a> fmt::Display
#[cfg(feature = "owning_ref")]
unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> StableAddress for RwLockWriteGuard<'a, R, T> {}

/// An RAII rwlock guard returned by the `Arc` locking operations on `RwLock`. This is similar to the
/// `RwLockWriteGuard` struct, except instead of using a reference to unlock the `RwLock` it uses an
/// `Arc<RwLock>`. This has several advantages, most notably that it has an `'static` lifetime.
/// An RAII rwlock guard returned by the `Arc` locking operations on `RwLock`.
/// This is similar to the `RwLockWriteGuard` struct, except instead of using a reference to unlock the `RwLock`
/// it uses an `Arc<RwLock>`. This has several advantages, most notably that it has an `'static` lifetime.
#[cfg(feature = "arc_lock")]
#[must_use = "if unused the RwLock will immediately unlock"]
pub struct ArcRwLockWriteGuard<R: RawRwLock, T: ?Sized> {
Expand Down Expand Up @@ -1747,8 +1748,8 @@ impl<R: RawRwLockFair, T: ?Sized> ArcRwLockWriteGuard<R, T> {
}

// SAFETY: prevent the Arc from leaking memory
let s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&s.rwlock) };
let mut s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&mut s.rwlock) };
}

/// Temporarily unlocks the `RwLock` to execute the given function.
Expand Down Expand Up @@ -2056,9 +2057,10 @@ unsafe impl<'a, R: RawRwLockUpgrade + 'a, T: ?Sized + 'a> StableAddress
{
}

/// An RAII rwlock guard returned by the `Arc` locking operations on `RwLock`. This is similar to the
/// `RwLockUpgradableReadGuard` struct, except instead of using a reference to unlock the `RwLock` it uses an
/// `Arc<RwLock>`. This has several advantages, most notably that it has an `'static` lifetime.
/// An RAII rwlock guard returned by the `Arc` locking operations on `RwLock`.
/// This is similar to the `RwLockUpgradableReadGuard` struct, except instead of using a reference to unlock the
/// `RwLock` it uses an `Arc<RwLock>`. This has several advantages, most notably that it has an `'static`
/// lifetime.
#[cfg(feature = "arc_lock")]
#[must_use = "if unused the RwLock will immediately unlock"]
pub struct ArcRwLockUpgradableReadGuard<R: RawRwLockUpgrade, T: ?Sized> {
Expand Down Expand Up @@ -2141,8 +2143,8 @@ impl<R: RawRwLockUpgradeFair, T: ?Sized> ArcRwLockUpgradableReadGuard<R, T> {
}

// SAFETY: make sure we decrement the refcount properly
let s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&s.rwlock) };
let mut s = ManuallyDrop::new(s);
unsafe { ptr::drop_in_place(&mut s.rwlock) };
}

/// Temporarily unlocks the `RwLock` to execute the given function.
Expand Down

0 comments on commit 8b0eb2f

Please sign in to comment.