Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arc_lock feature, with guards that can be accessed from inside of Arc #291

Merged
merged 7 commits into from Aug 1, 2021
Merged

Conversation

notgull
Copy link
Contributor

@notgull notgull commented Jul 29, 2021

Resolves #273.

This adds guards for Mutex and RwLock that allow it to be used from inside of an Arc, without lifetime hurdles.

Copy link
Owner

@Amanieu Amanieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Could you extend this to ReentrantMutex and RwLock as well?

/// `Arc` and the resulting mutex guard has no lifetime requirements.
#[cfg(feature = "arc_lock")]
#[inline]
pub fn try_lock_for_arc(this: &Arc<Self>, timeout: R::Duration) -> Option<ArcMutexGuard<R, T>> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try_lock_arc_for sounds better here.

/// an `Arc` and the resulting mutex guard has no lifetime requirements.
#[cfg(feature = "arc_lock")]
#[inline]
pub fn try_lock_until_arc(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -583,6 +658,112 @@ 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`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split the first sentence into a separate paragraph. This summary is shown in the module documentation index.

/// and the resulting mutex guard has no lifetime requirements.
#[cfg(feature = "arc_lock")]
#[inline]
pub fn lock_arc(this: &Arc<Self>) -> ArcMutexGuard<R, T> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn lock_arc(this: &Arc<Self>) -> ArcMutexGuard<R, T> {
pub fn lock_arc(self: &Arc<Self>) -> ArcMutexGuard<R, T> {

You can use self here which allows lock_arc to be called with dot syntax.

@notgull notgull marked this pull request as ready for review July 30, 2021 18:11
@Amanieu
Copy link
Owner

Amanieu commented Jul 31, 2021

Great work! Can you update the CI script so that the arc_lock feature is tested?

@notgull
Copy link
Contributor Author

notgull commented Jul 31, 2021

It doesn't seem like you can use Arc in self without an MSRV bump, unfortunately.

@Amanieu Amanieu merged commit 5cb2c0a into Amanieu:master Aug 1, 2021
@Amanieu
Copy link
Owner

Amanieu commented Aug 1, 2021

It's fine I'll just bump the MSRV for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add arc-based mutex locks to the lock_api crate
2 participants