Struct jack::RingBuffer [−][src]
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
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,