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);

Methods

impl RingBuffer
[src]

[src]

Allocates a ringbuffer of a specified size.

[src]

Lock a ringbuffer data block into memory.

[src]

Resets the ring buffer, making an empty buffer. Not thread safe.

[src]

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

[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]

[src]

Executes the destructor for this type. Read more