Struct jack::RingBuffer[][src]

pub struct RingBuffer(_);
Expand description

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 = [0_u8, 1, 2, 3];
let num = writer.write_buffer(&buf);
assert_eq!(num, buf.len());

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

Implementations

Allocates a ringbuffer of a specified size.

Lock a ringbuffer data block into memory.

Resets the ring buffer, making an empty buffer.

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

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

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.