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 RwLockWriteGuard::{downgrade_map, try_downgrade_map}. #5527

Merged
merged 5 commits into from Mar 8, 2023

Commits on Mar 7, 2023

  1. Add RwLockWriteGuard::{downgrade_map, try_downgrade_map}.

    `downgrade_map` can already be made using a combination of `RwLockWriteGuard::downgrade` and `RwLockReadGuard::map`, but this version runs `f` *before* downgrading, in case it's useful for anyone and just for completion's sake.
    
    The real use case is with `try_downgrade_map`. In this case, we run `f` *before* we downgrade, so we can return the write lock in case it returns `None`. This isn't implementable in safe code, at least not without one of the following tradeoffs:
    * Call `f` twice: Not always doable, when it's expensive or not idempotent.
    * Downgrade, call `f`, then re-lock if it returned `None`: If you're doing double-checked locking, this goes against the whole point of it, because you unlock and so state might have changed in the meantime.
    Zenithsiz committed Mar 7, 2023
    Copy the full SHA
    91fe74a View commit details
    Browse the repository at this point in the history
  2. Fixed RwLockWriteGuard::{downgrade_map, try_downgrade_map} not prop…

    …erly downgrading.
    
    `RwLockWriteGuard::{downgrade_map, try_downgrade_map}` doctests now test whether a read lock can be obtained afterwards.
    Zenithsiz committed Mar 7, 2023
    Copy the full SHA
    180e2d3 View commit details
    Browse the repository at this point in the history
  3. Added OwnedRwLockWriteGuard::{downgrade_map, try_downgrade_map}.

    These are mirrors of the existing methods on `RwLockLockWriteGuard`.
    Zenithsiz committed Mar 7, 2023
    Copy the full SHA
    6f636d5 View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    cd5e3cb View commit details
    Browse the repository at this point in the history
  5. Copy the full SHA
    f9f2930 View commit details
    Browse the repository at this point in the history