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

sync: Implement map methods of parking_lot fame #2771

Merged
merged 2 commits into from
Aug 27, 2020

Conversation

udoprog
Copy link
Contributor

@udoprog udoprog commented Aug 17, 2020

This is a backport to 0.2.x of #2445 because that's where I currently need it.

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

Since this was approved for 0.3, I'm +1 on the backport!

@Darksonn Darksonn added A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-sync Module: tokio/sync labels Aug 23, 2020
@udoprog udoprog force-pushed the tokio2-rwlock-map branch from 8f076c5 to 835516f Compare August 26, 2020 18:53
Generally, this mimics the way `MappedRwLock*Guard`s are implemented in
`parking_lot`. By storing a raw pointer in the guards themselves
referencing the mapped data and maintaining type invariants through
`PhantomData`. I didn't try to think too much about this, so if someone
has objections I'd love to hear them.

I've also dropped the internal use of `ReleasingPermit`, since it made
the guards unecessarily large. The number of permits that need to be
released are already known by the guards themselves, and is instead
governed directly in the relevant `Drop` impls.  This has the benefit of
making the guards as small as possible, for the non-mapped variants this
means a single reference is enough.

`fmt::Debug` impls have been adjusted to behave exactly like the
delegating impls in `parking_lot`. `fmt::Display` impls have been added
for all guard types which behave the same. This does change the format
of debug impls, for which I'm not sure if we provide any guarantees.
@udoprog udoprog force-pushed the tokio2-rwlock-map branch from 835516f to 0c7d16f Compare August 26, 2020 18:55
@Darksonn Darksonn merged commit f0328f7 into tokio-rs:v0.2.x Aug 27, 2020
@udoprog udoprog deleted the tokio2-rwlock-map branch August 27, 2020 07:33
@Darksonn Darksonn mentioned this pull request Nov 10, 2020
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 C-enhancement Category: A PR with an enhancement or bugfix. M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants