Skip to content

feat(rwlock): add an upgradable readers-writer lock - #366

Open
Kaileshwar16 wants to merge 1 commit into
apache:mainfrom
Kaileshwar16:feat/169-upgradable-rwlock
Open

Kaileshwar16 wants to merge 1 commit into
apache:mainfrom
Kaileshwar16:feat/169-upgradable-rwlock

Conversation

@Kaileshwar16

Copy link
Copy Markdown
Contributor

Closes #169.

Add UpgradableRwLock with ordinary readers, exclusive writers, and one upgradable
reader. Support asynchronous upgrade, guard-preserving try_upgrade(), and downgrade to
an ordinary reader.

Cancelling a pending upgrade releases the consumed guard and its permits. Include rustdoc
examples and deterministic tests for ordering, cancellation, reader limits, cross-thread
visibility, and guard traits.

Design Notes

Reuse the existing RwLock and semaphore implementation. Writers and upgradable readers
acquire a FIFO reservation before requesting data permits, preventing an upgrade from
queuing behind a writer waiting for the upgrader’s read permit.

Ordering is FIFO within each queue, rather than globally: ordinary readers can pass
writers waiting for the reservation. Existing RwLock behavior remains unchanged.

Validation:

  • cargo x lint and cargo x check passed.
  • cargo x test: 625 passed.
  • cargo x miri: 194 passed, 10 existing skips.
  • All 24 feature tests passed 20 repetitions and four Miri seeds.

This is an initial implementation intended to help settle the API design in #169. I'd especially appreciate feedback on the two-queue fairness model, cancellation semantics for a pending upgrade, and whether borrowed guards are sufficient for the first version. I'm happy to adjust the design based on maintainer feedback.

This branch has not been deployed

No deployments
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.

Provide an upgradable readers-writer lock

1 participant