Repository navigation
refactor: clarify waiter states and simplify synchronization internals - #429
Merged
tisonkun merged 7 commits intoNov 18, 2026
Merged
Conversation
Pair the waiting future with its waker in the acquisition request. Each request now determines where to queue its shortfall, so reduction debt takes priority over pending acquisitions.
Let cancellation take ownership of a waiter by ID. Callers can then return its permits or pass on its notification, while notification alone still leaves a detached node for the future to claim.
A queued reservation owns a waker until it receives capacity. Represent that transition with two states so cancellation can distinguish an unclaimed grant from a sender still waiting for a slot.
Keep the initialized-entry filter under the table lock and clone the value in get after unlocking. The lookup also owns the borrowed-key hash and comparison used by the cancellation regression test.
Use a single count for acquisition and release across borrowed, owned, and mapped guards, and derive the initial balance from that count plus one spare permit.
The waitgroup takes exclusive access to its waiter list. Remove the unused read and get_mut methods from its lock wrapper and let dead-code checks apply to the module.
Derive the semaphore capacity in both constructors from the initializer permit count plus one spare. This keeps the capacity and acquisition paths tied to the same exclusivity rule.
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
WaitListso cancellation paths can take the node and handle its notification or capacity in one place.OnceMap::get, name the permits held by each mutex guard and eachOnceCellinitializer, and remove unused methods from the waitgroup's internal lock.Verified with
cargo x test,cargo x check, andcargo x lint.