pub struct ThreadBufferRegistry { /* private fields */ }Expand description
Lock-free thread buffer registry.
§Design
- Fixed-size
AtomicPtrarray with capacityMAX_THREADS. - Writer (application thread): atomic
fetch_addto claim a slot index, thenstorethe 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
impl ThreadBufferRegistry
Sourcepub fn register(&self, thread_buffer: *mut ThreadBuffer)
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).
Sourcepub fn get(&self, index: usize) -> *mut ThreadBuffer
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).
Sourcepub fn clear_slot(&self, index: usize)
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
impl Default for ThreadBufferRegistry
impl Sync for ThreadBufferRegistry
Auto Trait Implementations§
impl !Freeze for ThreadBufferRegistry
impl RefUnwindSafe for ThreadBufferRegistry
impl Send for ThreadBufferRegistry
impl Unpin for ThreadBufferRegistry
impl UnsafeUnpin for ThreadBufferRegistry
impl UnwindSafe for ThreadBufferRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more