Skip to main content

Module blocking_rw_lock

Module blocking_rw_lock 

Source
Expand description

BlockingRWLock: cross-process reader-writer lock with a kernel-park slow path via CrossProcessWaker.

Composes crate::shared_rw_lock::SharedRWLock with one CrossProcessWaker plus a small mmap-backed wakeup-generation counter. The hot path delegates to try_read_lock / try_write_lock (single CAS each). The contention slow path differs from the existing primitive:

  • SharedRWLock::read_lock / write_lock spin → yield → sleep(50us) indefinitely until the lock becomes available. The sleep tail burns CPU on each wake-up tick AND can miss an unlock by up to 50us.
  • BlockingRWLock::read_park / write_park register in the waker at the current generation, then park in the kernel. The kernel returns within microseconds of the next unlock.

Both readers and writers park on the SAME waker; an unlock fires wake_all so the contending side picks up the lock according to the underlying writer-priority policy.

Structs§

BlockingRWLock
Cross-process reader-writer lock with kernel-park slow path.
BlockingReadGuard
RAII guard for a held read-lock. Drops to release.
BlockingWriteGuard
RAII guard for a held write-lock. Drops to release.

Enums§

BlockingRWLockError
Errors returned by BlockingRWLock operations.