Struct bounded_spsc_queue::Buffer
[−]
[src]
#[repr(C)]pub struct Buffer<T> { /* fields omitted */ }
The internal memory buffer used by the queue.
Buffer holds a pointer to allocated memory which represents the bounded ring buffer, as well as a head and tail atomicUsize which the producer and consumer use to track location in the ring.
Methods
impl<T> Buffer<T>
[src]
fn try_pop(&self) -> Option<T>
Attempt to pop a value off the buffer.
If the buffer is empty, this method will not block. Instead, it will return None
signifying the buffer was empty. The caller may then decide what to do next (e.g. spin-wait,
sleep, process something else, etc)
Examples
// Attempt to pop off a value let t = buffer.try_pop(); match t { Some(v) => {}, // Got a value None => {} // Buffer empty, try again later }
fn pop(&self) -> T
Pop a value off the buffer.
This method will block until the buffer is non-empty. The waiting strategy is a simple
spin-wait and will repeatedly call try_pop()
until a value is available. If you do not
want a spin-wait burning CPU, you should call try_pop()
directly and implement a different
waiting strategy.
Examples
// Block until a value is ready let t = buffer.pop();
fn try_push(&self, v: T) -> Option<T>
Attempt to push a value onto the buffer.
If the buffer is full, this method will not block. Instead, it will return Some(v)
, where
v
was the value attempting to be pushed onto the buffer. If the value was successfully
pushed onto the buffer, None
will be returned signifying success.
Examples
// Attempt to push a value onto the buffer let t = buffer.try_push(123); match t { Some(v) => {}, // Buffer was full, try again later None => {} // Value was successfully pushed onto the buffer }
fn push(&self, v: T)
Push a value onto the buffer.
This method will block until the buffer is non-full. The waiting strategy is a simple
spin-wait and will repeatedly call try_push()
until the value can be added. If you do not
want a spin-wait burning CPU, you should call try_push()
directly and implement a different
waiting strategy.
Examples
// Block until we can push this value onto the buffer buffer.try_push(123);
Trait Implementations
impl<T: Sync> Sync for Buffer<T>
[src]
impl<T> Drop for Buffer<T>
[src]
Handles deallocation of heap memory when the buffer is dropped