Skip to main content

ThreadBufferRegistry

Struct ThreadBufferRegistry 

Source
pub struct ThreadBufferRegistry { /* private fields */ }
Expand description

Lock-free thread buffer registry.

§Design

  • Fixed-size AtomicPtr array with capacity MAX_THREADS.
  • Writer (application thread): atomic fetch_add to claim a slot index, then store the pointer.
  • Reader (poller): iterates 0..count, loading each slot’s pointer.
  • No Mutex, no heap allocation; registration path is a single atomic operation.

The writer appends once during preallocate() (fetch_add + store), and the reader traverses lock-free during poll(). Zero contention.

Implementations§

Source§

impl ThreadBufferRegistry

Source

pub const fn new() -> Self

Creates a new empty registry.

Source

pub fn register(&self, thread_buffer: *mut ThreadBuffer)

Registers a ThreadBuffer. Called by the writer side, once per thread.

Internally performs a single fetch_add (claim slot) + a single store (write pointer).

Source

pub fn count(&self) -> usize

Returns the current number of registered slots.

Source

pub fn get(&self, index: usize) -> *mut ThreadBuffer

Loads the pointer at the given slot index. Called by the reader side, lock-free.

Returns null if the slot has not yet been fully written (a very brief window).

Source

pub fn clear_slot(&self, index: usize)

Clears a slot by storing null (called by the poller after reclaiming a ThreadBuffer).

Trait Implementations§

Source§

impl Default for ThreadBufferRegistry

Source§

fn default() -> Self

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

impl Sync for ThreadBufferRegistry

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.