FabricQueue

Struct FabricQueue 

Source
pub struct FabricQueue<T> { /* private fields */ }
Expand description

A bounded SPSC ring buffer stored in leased fabric memory.

The queue owns its MemLease and releases it on drop. Elements are stored in FIFO order: push() appends to the tail, pop() reads from the head.

§Non-blocking semantics

  • push() returns Ok(false) when the queue is full.
  • pop() returns Ok(None) when the queue is empty.

Neither operation blocks or retries.

§Future direction: MPMC

This queue is currently single-producer single-consumer. A future MPMC variant would replace the plain head/tail fields with compare-and-swap (CAS) atomic operations on the remote memory, or alternatively use a lock-based protocol with a lease-scoped mutex in the header region. MPMC support is not yet implemented.

§Example

use grafos_collections::queue::FabricQueue;

let mut q: FabricQueue<u32> = FabricQueue::with_capacity(8, 16)?;
q.push(&10)?;
q.push(&20)?;
assert_eq!(q.pop()?, Some(10));
assert_eq!(q.pop()?, Some(20));
assert_eq!(q.pop()?, None);

Implementations§

Source§

impl<T: Serialize + DeserializeOwned> FabricQueue<T>

Source

pub fn new(lease: MemLease, capacity: usize, stride: usize) -> Result<Self>

Create a new queue over the given lease.

capacity is the total number of slots. stride is the slot width in bytes (must accommodate 4-byte length prefix plus serialized element). One slot is reserved for the empty/full distinction, so the usable capacity is capacity - 1.

§Errors

Returns FabricError::CapacityExceeded if the arena is too small to hold the header (32 bytes) plus capacity * stride bytes.

Source

pub fn with_capacity(capacity: usize, stride: usize) -> Result<Self>

Create a new queue by acquiring a lease sized for capacity elements of stride bytes each.

Convenience constructor that acquires a lease via MemBuilder and then calls FabricQueue::new.

§Errors

Returns FabricError::CapacityExceeded if the host cannot provide a large enough arena.

Source

pub fn push(&mut self, item: &T) -> Result<bool>

Push an element onto the back of the queue.

Returns Ok(true) if the element was enqueued, Ok(false) if the queue is full. Does not block.

§Errors
Source

pub fn pop(&mut self) -> Result<Option<T>>

Pop an element from the front of the queue.

Returns Ok(Some(item)) if an element was dequeued, Ok(None) if the queue is empty. Does not block.

§Errors

Returns FabricError::IoError if the remote read or deserialization fails.

Source

pub fn len(&self) -> usize

Returns the number of elements currently in the queue.

Source

pub fn is_empty(&self) -> bool

Returns true if the queue contains no elements.

Source

pub fn is_full(&self) -> bool

Returns true if the queue is full.

Source

pub fn lease_id(&self) -> u128

Returns the lease ID of the memory lease for external renewal management (e.g. via [grafos_leasekit::RenewalManager]).

Source

pub fn expires_at_unix_secs(&self) -> u64

Returns the expiry time (unix seconds) of the memory lease for external renewal management.

Source

pub fn max_len(&self) -> usize

Returns the maximum number of elements the queue can hold.

This is capacity - 1 since one slot is reserved for the empty/full distinction.

Auto Trait Implementations§

§

impl<T> Freeze for FabricQueue<T>

§

impl<T> !RefUnwindSafe for FabricQueue<T>

§

impl<T> !Send for FabricQueue<T>

§

impl<T> !Sync for FabricQueue<T>

§

impl<T> Unpin for FabricQueue<T>
where T: Unpin,

§

impl<T> !UnwindSafe for FabricQueue<T>

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.