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]

[src]

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
}

[src]

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>.

[src]

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

[src]

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
}

[src]

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

[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl<T> !Send for Buffer<T>