refactor: rewrite RwLock guards around RAII access tokens - #289
Open
tisonkun wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rewrite RwLock's eight guard types around private RAII access tokens. Guards now move their access token when projecting data or downgrading, eliminating
ManuallyDropand rawArcextraction. Preserve the public API, semaphore-based FIFO scheduling, and guard sizes.Apply ASF source headers to the substantially rewritten files while retaining Tokio copyright, MIT attribution, and pinned upstream mappings. Update
LICENSEwith the concrete implementation changes and remove the RwLock exemptions from the header checker. Rewrite the documentation around acquisition, projection, and owned lifetimes.Design Notes
Read and write tokens own the obligation to release permits. Their owners are borrowed locks, borrowed semaphores for projections, or owned
Arcs; token transfer usesOption::takewithout extra allocation or reference-count increments. Downgrade creates the read token before releasing other permits, so a panicking wake callback cannot leak the retained read access or owned lock reference. The regression reproduces on v0.7.1 and passes with this rewrite.Validation: workspace tests on stable and Rust 1.86,
cargo x check,cargo x miri, and 196 semver checks against 0.7.1 passed. Clippy, rustfmt, Taplo, typos, Hawkeye, and rustdoc passed (Taplo required running outside the macOS sandbox). Tests cover projection unwind/failure, all four downgrade forms, reader limits, queue ordering, cancellation before guard construction, and guard trait bounds. A local aarch64 layout comparison confirmed unchanged size/alignment for all eight guards with sized and unsized values.