Struct RingBuffer

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

RingBuffer wraps a IOBuffer shared region and mapping that uses the ring buffer discipline.

Implementations§

Source§

impl RingBuffer

Source

pub fn create(capacity: usize) -> Reader

Returns a new RingBuffer and Reader. capacity must be a multiple of the page size and should be at least MAX_MESSAGE_SIZE. The capacity does not include the additional page used to store the head and tail indices.

Source

pub fn new_iob_writer(&self, tag: u64) -> Result<(Iob, Iob), Status>

Returns an IOBuffer that can be used to write to the ring buffer. A tuple is returned; the first IOBuffer in the tuple can be written to. The second IOBuffer is the peer and cannot be written to or mapped but it can be monitored for peer closed.

Source

pub fn capacity(&self) -> usize

Returns the capacity of the ring buffer.

Source

pub fn head(&self) -> u64

Returns the value of the head pointer, read with Acquire ordering (which will synchronise with an update to the head pointer in the kernel that uses Release ordering).

Source

pub fn tail(&self) -> u64

Returns the value of the tail pointer, read with Acquire ordering (which will synchronise with an update to the tail via increment_tail below; the kernel never changes the tail pointer).

Source

pub fn increment_tail(&self, amount: usize)

Increments the tail pointer, synchronized with Release ordering (which will synchronise with the kernel that reads the tail pointer using Acquire ordering). amount should always be a multiple of 8. See also ring_buffer_record_len.

Source

pub unsafe fn read<T>(&self, index: u64) -> T

Reads T at index in the buffer.

§SAFETY

index must have the same alignment as T. The read is non-atomic which means it is undefined behaviour if there is concurrent write access to the same location (across all processes).

Source

pub unsafe fn first_message_in( &self, range: Range<u64>, ) -> Result<(u64, &[u8]), Error>

Returns a slice for the first message in range.

§SAFETY

The reads are non-atomic so there can be no other concurrent write access to the same range (across all processes). The returned slice will only remain valid so long as there is no other concurrent write access to the range.

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.