Struct jack::RingBuffer[][src]

pub struct RingBuffer(_);

A lock-free ringbuffer. The key attribute of a ringbuffer is that it can be safely accessed by two threads simultaneously, one reading from the buffer and the other writing to it - without using any synchronization or mutual exclusion primitives. For this to work correctly, there can only be a single reader and a single writer thread. Their identities cannot be interchanged.

Example

let ringbuf = jack::RingBuffer::new(1024).unwrap();
let (mut reader, mut writer) = ringbuf.into_reader_writer();

let buf = [0u8, 1, 2, 3];
let num = writer.write_buffer(&buf);
assert_eq!(num, buf.len());

// Potentially in a another thread:
let mut outbuf = [0u8; 8];
let num = reader.read_buffer(&mut outbuf);

Implementations

impl RingBuffer[src]

pub fn new(size: usize) -> Result<Self, ()>[src]

Allocates a ringbuffer of a specified size.

pub fn mlock(&mut self)[src]

Lock a ringbuffer data block into memory.

pub fn reset(&mut self)[src]

Resets the ring buffer, making an empty buffer.

pub fn into_reader_writer(self) -> (RingBufferReader, RingBufferWriter)[src]

Create a reader and writer, to use the ring buffer.

pub fn from_reader_writer(r: RingBufferReader, w: RingBufferWriter) -> Self[src]

Re-create the ring buffer object from reader and writer. useful if you need to call reset. The reader and the writer pair must have been created from the same RingBuffer object. Not needed for deallocation, disposing of both reader and writer will deallocate buffer resources automatically.

panics if the reader and the writer were created from different RingBuffer objects.

Trait Implementations

impl Drop for RingBuffer[src]

impl Send for RingBuffer[src]

impl Sync for RingBuffer[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.