Skip to main content

RingBuffer

Struct RingBuffer 

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

A lock-free ring buffer for message passing.

The ring buffer uses atomic head/tail pointers for lock-free operation. Messages are stored inline after the entry header, or as descriptors pointing to shared region data.

Implementations§

Source§

impl RingBuffer

Source

pub fn new( region: RegionHandle, size: u32, max_msg_size: u32, buffer: *mut u8, buffer_len: usize, ) -> Result<Self>

Create a new ring buffer.

§Arguments
  • region - Handle to the backing region
  • size - Number of entries (must be power of 2)
  • max_msg_size - Maximum message size in bytes
  • buffer - Pointer to the ring buffer memory
  • buffer_len - Length of the buffer
§Errors

Returns InvalidParameter if size is not a power of 2.

Source

pub fn region(&self) -> RegionHandle

Returns the region handle.

Source

pub fn size(&self) -> u32

Returns the ring size.

Source

pub fn max_msg_size(&self) -> u32

Returns the maximum message size.

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<()>

Enqueue a message into the ring buffer.

§Arguments
  • data - Message payload
  • priority - Message priority
§Errors

Returns QueueFull if the ring is full. Returns MessageTooLarge if the message exceeds max_msg_size.

Source

pub fn enqueue_descriptor( &mut self, descriptor: &MessageDescriptor, priority: MsgPriority, ) -> Result<()>

Enqueue a descriptor into the ring buffer.

This is used for zero-copy message passing when the data is in a shared region.

§Arguments
  • descriptor - The message descriptor (region, offset, length)
  • priority - Message priority
§Errors

Returns QueueFull if the ring is full.

Source

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

Dequeue a message from the ring buffer.

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

On success, returns the ring entry header. For inline data, the actual data is copied to buf. For descriptors, the descriptor is in buf.

§Errors

Returns QueueEmpty if the ring is empty.

Source

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

Peek at the next entry without removing it.

Trait Implementations§

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.