Skip to main content

SharedQueue

Struct SharedQueue 

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

Lock-free single-producer, single-consumer queue in shared memory.

Each end is exclusive: the first send on a handle claims the queue’s sender endpoint and the first recv its receiver endpoint, through flags in the shared header, so two handles – in one process or several – can never both send or both receive. A handle may hold both ends. Claims release when the handle drops; a process killed while holding one leaves it held until the creator drops the segment.

Implementations§

Source§

impl<T: Pod> SharedQueue<T>

Source

pub fn create(name: &str, capacity: usize) -> Result<Self, IpcError>

Create a new shared queue under a name no live segment holds.

Fails with IpcError::AlreadyExists when the name is taken, so a second creator can never reinitialise the header under live handles.

T is bounded by bytemuck::Pod: shared-memory contents are written by one process and read as T by another, so the element type must be valid for every bit pattern (no bool/char/enum/reference discriminants a peer could corrupt into an invalid value).

§Errors

Returns IpcError::AlreadyExists for a taken name, IpcError::InvalidArgument for a zero capacity, an over-aligned T, or a size overflow, and the OS error otherwise.

Source

pub fn open(name: &str, capacity: usize) -> Result<Self, IpcError>

Open an existing shared queue. Fails with IpcError::InvalidArgument if the segment was created with a different capacity, which would otherwise map a view inconsistent with the creator’s and fault on access.

§Errors

Returns IpcError::InvalidArgument for a capacity mismatch (including a creator that has not finished initialising), and the OS error when the segment is missing or too small.

Source

pub fn send(&mut self, value: T) -> Result<(), SendError<T>>

Send a value.

The first call claims the queue’s sender endpoint for this handle; the claim is released when the handle drops.

§Errors

Returns the value inside SendError::Full when the ring is full, SendError::Closed when the queue is closed, and SendError::EndpointInUse when another handle already sends on this queue.

Source

pub fn recv(&mut self) -> Result<Option<T>, IpcError>

Receive a value, or None when the queue is empty.

The first call claims the queue’s receiver endpoint for this handle; the claim is released when the handle drops.

§Errors

Returns IpcError::EndpointInUse when another handle already receives on this queue.

Trait Implementations§

Source§

impl<T> Drop for SharedQueue<T>

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<T: Send> Send for SharedQueue<T>

Auto Trait Implementations§

§

impl<T> !Sync for SharedQueue<T>

§

impl<T> Freeze for SharedQueue<T>
where *mut T: Freeze,

§

impl<T> RefUnwindSafe for SharedQueue<T>

§

impl<T> Unpin for SharedQueue<T>
where *mut T: Unpin,

§

impl<T> UnsafeUnpin for SharedQueue<T>

§

impl<T> UnwindSafe for SharedQueue<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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.