Struct sync::spsc_queue::Queue[src]

pub struct Queue<T> {
    // some fields omitted
}

The single-producer single-consumer queue. This structure is not cloneable, but it can be safely shared in an Arc if it is guaranteed that there is only one popper and one pusher touching the queue at any one point in time.

Methods

impl<T: Send> Queue<T>

fn new(bound: uint) -> Queue<T>

Creates a new queue. The producer returned is connected to the consumer to push all data to the consumer.

Arguments

  • bound - This queue implementation is implemented with a linked list, and this means that a push is always a malloc. In order to amortize this cost, an internal cache of nodes is maintained to prevent a malloc from always being necessary. This bound is the limit on the size of the cache (if desired). If the value is 0, then the cache has no bound. Otherwise, the cache will never grow larger than bound (although the queue itself could be much larger.

fn push(&self, t: T)

Pushes a new value onto this queue. Note that to use this function safely, it must be externally guaranteed that there is only one pusher.

fn pop(&self) -> Option<T>

Attempts to pop a value from this queue. Remember that to use this type safely you must ensure that there is only one popper at a time.

fn peek<'a>(&'a self) -> Option<&'a mut T>

Attempts to peek at the head of the queue, returning None if the queue has no data currently

Trait Implementations

impl<T: Send> Drop for Queue<T>

fn drop(&mut self)