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
Conversation
There was a problem hiding this 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?
lock_api/src/mutex.rs
Outdated
/// `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>> { |
There was a problem hiding this comment.
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.
lock_api/src/mutex.rs
Outdated
/// an `Arc` and the resulting mutex guard has no lifetime requirements. | ||
#[cfg(feature = "arc_lock")] | ||
#[inline] | ||
pub fn try_lock_until_arc( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
lock_api/src/mutex.rs
Outdated
@@ -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` |
There was a problem hiding this comment.
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.
lock_api/src/mutex.rs
Outdated
/// and the resulting mutex guard has no lifetime requirements. | ||
#[cfg(feature = "arc_lock")] | ||
#[inline] | ||
pub fn lock_arc(this: &Arc<Self>) -> ArcMutexGuard<R, T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Great work! Can you update the CI script so that the |
It doesn't seem like you can use |
It's fine I'll just bump the MSRV for the next release. |
Resolves #273.
This adds guards for
Mutex
andRwLock
that allow it to be used from inside of anArc
, without lifetime hurdles.