Skip to content

Commit

Permalink
sync: Implement map methods of parking_lot fame
Browse files Browse the repository at this point in the history
I've introduced `MappedRwLockReadGuard` and `MappedRwLockWriteGuard`,
which are produced by the relevant `map` and `try_map` methods.

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.
  • Loading branch information
udoprog committed Jul 24, 2020
1 parent 94b64cd commit 51bdc6f
Showing 1 changed file with 296 additions and 36 deletions.
Loading

0 comments on commit 51bdc6f

Please sign in to comment.