pub struct ReaderRegistry { /* private fields */ }Expand description
Lock-free reader registration for tracking active epochs.
Replaces the original RwLock<HashMap<u64, u64>> with a fixed-size
array of cache-line-aligned AtomicU64 slots. Every operation is
O(1) amortised and fully lock-free:
register()— CAS-loop to claim an empty slotunregister()— single atomic store (SLOT_EMPTY)min_active_epoch()— relaxed scan of all slots, no locking
Implementations§
Source§impl ReaderRegistry
impl ReaderRegistry
pub fn new() -> Self
Sourcepub fn register(&self, epoch: u64) -> Option<u64>
pub fn register(&self, epoch: u64) -> Option<u64>
Register a reader at epoch. Returns the slot index (used as reader_id).
Cost: O(MAX_READER_SLOTS) worst-case scan, O(1) amortised with low occupancy. Fully lock-free — uses compare_exchange to claim an empty slot.
Returns None if all slots are exhausted. Callers must back-pressure
or retry after a brief yield — silently overwriting a slot would allow
the GC watermark to advance past a still-active reader’s epoch,
leading to use-after-free on version data.
Sourcepub fn unregister(&self, reader_id: u64)
pub fn unregister(&self, reader_id: u64)
Unregister a reader by slot index.
Cost: O(1), lock-free.
Sourcepub fn min_active_epoch(&self) -> Option<u64>
pub fn min_active_epoch(&self) -> Option<u64>
Compute the minimum epoch across all active readers, lock-free.
Cost: O(MAX_READER_SLOTS) with relaxed loads — no locking, no contention.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Get count of active readers.