Skip to content

refactor: clarify waiter states and simplify synchronization internals - #429

Merged
tisonkun merged 7 commits into
apache:mainfrom
tisonkun:codex/simplify-waiter-bookkeeping
Nov 18, 2026
Merged

tisonkun merged 7 commits into
apache:mainfrom
tisonkun:codex/simplify-waiter-bookkeeping

Conversation

@tisonkun

@tisonkun tisonkun commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Make semaphore requests and bounded MPSC reservations express who owns a queued permit and where the request belongs in the queue.
  • Move waiter removal into WaitList so cancellation paths can take the node and handle its notification or capacity in one place.
  • Make the initialized-entry requirement explicit in OnceMap::get, name the permits held by each mutex guard and each OnceCell initializer, and remove unused methods from the waitgroup's internal lock.

Verified with cargo x test, cargo x check, and cargo x lint.

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.
@tisonkun
tisonkun enabled auto-merge (squash) November 18, 2026 10:21
@tisonkun
tisonkun merged commit 9224af0 into apache:main Nov 18, 2026
9 checks passed
@tisonkun
tisonkun deleted the codex/simplify-waiter-bookkeeping branch November 18, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant