Skip to main content

LockFreeRing

Struct LockFreeRing 

Source
pub struct LockFreeRing {
    queue: ArrayQueue<Box<[u8]>>,
    slot_limit: usize,
    frames: Vec<PhysFrame>,
}
Expand description

A bounded lock-free message queue.

Internally uses [crossbeam_queue::ArrayQueue<Box<[u8]>>] for safe, tested message passing. Also allocates minimal physical frames for frame_phys_addrs() used by the shared-ring IPC syscall.

Fields§

§queue: ArrayQueue<Box<[u8]>>§slot_limit: usize§frames: Vec<PhysFrame>

Implementations§

Source§

impl LockFreeRing

Source

const DEFAULT_CAPACITY: u32 = 256

Default slot count.

Source

pub fn new(slot_count: u32, slot_size: usize) -> Result<Arc<Self>, RingError>

Create a new ring with slot_count slots for messages up to slot_size bytes.

Source

pub fn capacity(&self) -> u32

The number of slots in this ring.

Source

pub fn slot_size(&self) -> u32

The maximum message size in bytes.

Source

pub fn frame_phys_addrs(&self) -> Vec<u64>

Physical addresses of the backing frames (for IPC ring compat).

Source

pub fn write(&self, data: &[u8]) -> Result<(), RingError>

Write data into the ring. Returns Full if no slot is available, or MessageTooLarge if the data exceeds the slot capacity.

Source

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

Read one message from the ring into buf.

Source

pub fn try_write(&self, data: &[u8]) -> Result<(), RingError>

Non-blocking write.

Source

pub fn write_vectored(&self, bufs: &[&[u8]]) -> Result<(), RingError>

Write multiple buffers in a single slot (scatter-gather).

Source

pub fn try_read(&self, buf: &mut [u8]) -> Result<Option<usize>, RingError>

Non-blocking read. Returns Ok(None) when the ring is empty.

Source

pub fn notify_consumer_raw(&self)

Notify the consumer that new data is available. No-op under ArrayQueue (notification is handled by the caller).

Source

pub fn notify_producer_raw(&self)

Notify the producer that space has been freed. No-op under ArrayQueue.

Source

pub fn has_data(&self) -> bool

Returns true if the ring contains at least one message.

Source

pub fn has_space(&self) -> bool

Returns true if at least one slot is free.

Source

pub fn dma_buffer(&self, _slot_index: u32) -> Option<DmaBuffer>

DMA buffer descriptor.

ArrayQueue does not expose physical addresses; this method returns None. The NIC data plane uses dedicated hardware ring buffers.

Trait Implementations§

Source§

impl Debug for LockFreeRing

Source§

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

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

impl Drop for LockFreeRing

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl IpcConsumer for LockFreeRing

Source§

fn recv(&self, buf: &mut [u8]) -> Result<usize, IpcError>

Receive a message, blocking if the buffer is empty.
Source§

fn try_recv(&self, buf: &mut [u8]) -> Result<Option<usize>, IpcError>

Receive without blocking.
Source§

impl IpcNotification for LockFreeRing

Source§

fn notify_consumer(&self)

Notify the consumer that data is available.
Source§

fn notify_producer(&self)

Notify the producer that space is available.
Source§

fn wait_notification(&self) -> Result<(), IpcError>

Block until a notification arrives.
Source§

impl IpcProducer for LockFreeRing

Source§

fn send(&self, msg: &[u8]) -> Result<(), IpcError>

Send a message, blocking if the buffer is full.
Source§

fn try_send(&self, msg: &[u8]) -> Result<(), IpcError>

Send without blocking.
Source§

fn send_vectored(&self, bufs: &[&[u8]]) -> Result<(), IpcError>

Send using vectored I/O (scatter-gather). Read more
Source§

impl IpcTransport for LockFreeRing

Source§

fn level(&self) -> TransportLevel

The isolation level of this transport.
Source§

fn capabilities(&self) -> TransportCapabilities

Static capabilities of this transport.
Source§

fn name(&self) -> &'static str

Human-readable name for debugging / profiling.
Source§

impl Send for LockFreeRing

Source§

impl Sync for LockFreeRing

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.