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 OwnedRwLockReadGuard and OwnedRwLockWriteGuard #3340

Merged
merged 7 commits into from Mar 23, 2021

Conversation

SabrinaJewson
Copy link
Contributor

I did not add mapping functions as it's not possible to implement them soundly without adding another generic parameter to the guards, which I will leave to another PR. I implemented OwnedRwLockWriteGuard::downgrade as a method because RwLockWriteGuard::downgrade is a method - but that was probably a mistake, so I'm not sure.

Fixes: #3327

Motivation

The feature is already present for mutexes, and it is useful in some scenarios with RwLocks.

Solution

Add OwnedRwLockReadGuard and OwnedRwLockWriteGuard, which are variants of RwLockReadGuard and RwLockWriteGuard that store an Arc.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Dec 25, 2020
@Darksonn
Copy link
Contributor

Please update your PR to have separate RwLockWriteGuard and RwLockMappedWriteGuard types as discussed in #3344, #3345 and #3348. Also note the reorganization in #3348, which will likely be merged first, and which you may want to wait for.

@SabrinaJewson
Copy link
Contributor Author

I've rebased on #3348 now.

I did not add mapping functions as it's not possible to implement them
soundly without adding another generic parameter to the guards, which I
will leave to another PR.

Fixes: tokio-rs#3327
@SabrinaJewson
Copy link
Contributor Author

After another rebase, it should finally be good to review now. I didn't choose the best of times to make this PR 😅.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Hey, sorry for the delay in reviewing. I don't have any comments besides the one below.

tokio/src/sync/rwlock/owned_read_guard.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

This seems ok to me.

@Darksonn Darksonn merged commit 0dc4769 into tokio-rs:master Mar 23, 2021
@Darksonn Darksonn mentioned this pull request Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add OwnedRwLockReadGuard + OwnedRwLockWriteGuard
2 participants