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]
impl<T> Buffer<T>
pub fn try_pop(&self) -> Option<T>
[src]
pub 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 }
pub fn skip_n(&self, n: usize) -> usize
[src]
pub fn skip_n(&self, n: usize) -> usize
Attempts to pop (and discard) at most n
values off the buffer.
Returns the amount of values successfully skipped.
Safety
WARNING: This will leak at most n
values from the buffer, i.e. the destructors of the
objects skipped over will not be called. This function is intended to be used on buffers that
contain non-Drop
data, such as a Buffer<f32>
.
pub fn pop(&self) -> T
[src]
pub 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();
pub fn try_push(&self, v: T) -> Option<T>
[src]
pub 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 }
pub fn push(&self, v: T)
[src]
pub 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: Sync> Sync for Buffer<T>
impl<T> Drop for Buffer<T>
[src]
impl<T> Drop for Buffer<T>
Handles deallocation of heap memory when the buffer is dropped