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
impl RingBuffer
Sourcepub fn create(capacity: usize) -> Reader
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.
Sourcepub fn new_iob_writer(&self, tag: u64) -> Result<(Iob, Iob), Status>
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.
Sourcepub fn head(&self) -> u64
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).
Sourcepub fn tail(&self) -> u64
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).
Sourcepub fn increment_tail(&self, amount: usize)
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
.
Sourcepub unsafe fn read<T>(&self, index: u64) -> T
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).
Sourcepub unsafe fn first_message_in(
&self,
range: Range<u64>,
) -> Result<(u64, &[u8]), Error>
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.