Skip to main content

ReaderRegistry

Struct ReaderRegistry 

Source
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 slot
  • unregister() — single atomic store (SLOT_EMPTY)
  • min_active_epoch() — relaxed scan of all slots, no locking

Implementations§

Source§

impl ReaderRegistry

Source

pub fn new() -> Self

Source

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.

Source

pub fn unregister(&self, reader_id: u64)

Unregister a reader by slot index.

Cost: O(1), lock-free.

Source

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.

Source

pub fn active_count(&self) -> usize

Get count of active readers.

Trait Implementations§

Source§

impl Debug for ReaderRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ReaderRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.