Skip to main content

OptimizedRingBuffer

Struct OptimizedRingBuffer 

Source
pub struct OptimizedRingBuffer<const N: usize = 64> { /* private fields */ }
Expand description

Optimized lock-free ring buffer with power-of-2 size.

Uses atomic operations for thread-safe enqueue/dequeue. Power-of-2 size enables fast modulo via bitwise AND.

Implementations§

Source§

impl<const N: usize> OptimizedRingBuffer<N>

Source

pub fn new(region: RegionHandle) -> Self

Creates a new optimized ring buffer.

§Arguments
  • region - Handle to the backing region
§Panics

Panics if N is not a power of 2.

Source

pub fn region(&self) -> RegionHandle

Returns the region handle.

Source

pub const fn capacity(&self) -> usize

Returns the ring capacity.

Source

pub fn len(&self) -> u32

Returns the number of entries currently in the ring.

Source

pub fn is_empty(&self) -> bool

Returns true if the ring is empty.

Source

pub fn is_full(&self) -> bool

Returns true if the ring is full.

Source

pub fn available(&self) -> u32

Returns the number of free slots.

Source

pub fn enqueue(&mut self, data: &[u8], priority: MsgPriority) -> Result<()>

Enqueues a message into the ring buffer (<200ns target).

§Arguments
  • data - Message payload (max 56 bytes for inline)
  • priority - Message priority
§Errors

Returns QueueFull if the ring is full. Returns MessageTooLarge if the message exceeds inline limit.

Source

pub fn dequeue(&mut self, buf: &mut [u8]) -> Result<(OptimizedRingEntry, usize)>

Dequeues a message from the ring buffer (<200ns target).

§Arguments
  • buf - Buffer to receive the message data
§Returns

On success, returns the entry header and number of bytes copied.

§Errors

Returns QueueEmpty if the ring is empty.

Source

pub fn peek(&self) -> Option<&OptimizedRingEntry>

Peeks at the next entry without removing it.

Source

pub fn try_enqueue(&mut self, data: &[u8], priority: MsgPriority) -> Result<()>

Tries to enqueue without blocking, returns immediately.

Source

pub fn try_dequeue( &mut self, buf: &mut [u8], ) -> Result<(OptimizedRingEntry, usize)>

Tries to dequeue without blocking, returns immediately.

Source

pub fn clear(&mut self)

Clears all entries from the ring.

Trait Implementations§

Source§

impl<const N: usize> Default for OptimizedRingBuffer<N>

Source§

fn default() -> Self

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

impl<const N: usize> Send for OptimizedRingBuffer<N>

Source§

impl<const N: usize> Sync for OptimizedRingBuffer<N>

Auto Trait Implementations§

§

impl<const N: usize = 64> !Freeze for OptimizedRingBuffer<N>

§

impl<const N: usize> RefUnwindSafe for OptimizedRingBuffer<N>

§

impl<const N: usize> Unpin for OptimizedRingBuffer<N>

§

impl<const N: usize> UnsafeUnpin for OptimizedRingBuffer<N>

§

impl<const N: usize> UnwindSafe for OptimizedRingBuffer<N>

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.