Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file.

### New features

* Add `rwlock::UpgradableRwLock` with a single upgradable reader, atomic upgrade and downgrade, and cancellation that releases a pending upgrade's guard; writers and upgradable readers share a FIFO reservation while ordinary readers use the data-permit queue.
* Add bounded MPMC `reserve` and `try_reserve` methods returning a borrowed `Permit`, so callers can wait for capacity before constructing a value; sends and reservations receive capacity in wait-queue order, and unused permits release it.

### Bug fixes
Expand Down
11 changes: 9 additions & 2 deletions asyncband/src/rwlock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
//! A write guard allows mutation and excludes every other guard. Both release their access on
//! drop, including during unwinding; a panic does not poison the lock.
//!
//! Waiting requests are served in queue order. A queued writer blocks readers behind it, even
//! while earlier readers still hold the lock. Consequently, keeping a read guard while waiting
//! [`RwLock`] serves waiting requests in queue order. A queued writer blocks readers behind it,
//! even while earlier readers still hold the lock. Consequently, keeping a read guard while waiting
//! for a write guard, or for another read behind a queued writer, can deadlock. The `try_` methods
//! never wait or reserve a queue position. Dropping a pending acquisition cancels its request;
//! a subsequent acquisition starts again at the back of the queue.
//!
//! [`UpgradableRwLock`] is a separate lock for inspecting a value before deciding to mutate it.
//! It reserves one reader's ability to upgrade and has its own [ordering
//! policy](UpgradableRwLock#ordering).
//!
//! # Updating and inspecting
//!
//! ```
Expand Down Expand Up @@ -114,6 +118,7 @@ mod owned_mapped_write_guard;
mod owned_read_guard;
mod owned_write_guard;
mod read_guard;
mod upgradable;
mod write_guard;

pub use self::mapped_read_guard::MappedRwLockReadGuard;
Expand All @@ -123,6 +128,8 @@ pub use self::owned_mapped_write_guard::OwnedMappedRwLockWriteGuard;
pub use self::owned_read_guard::OwnedRwLockReadGuard;
pub use self::owned_write_guard::OwnedRwLockWriteGuard;
pub use self::read_guard::RwLockReadGuard;
pub use self::upgradable::RwLockUpgradableReadGuard;
pub use self::upgradable::UpgradableRwLock;
pub use self::write_guard::RwLockWriteGuard;

/// A value with fair, asynchronous shared or exclusive access.
Expand Down
Loading