[][src]Struct atomicring::AtomicRingQueue

pub struct AtomicRingQueue<T> { /* fields omitted */ }

A constant-size almost lock-free concurrent ring buffer with blocking poll support

See AtomicRingQueue for implementation details

Examples

 // create an AtomicRingQueue with capacity of 1024 elements
 let ring = ::atomicring::AtomicRingQueue::with_capacity(900);

 // try_pop removes an element of the buffer and returns None if the buffer is empty
 assert_eq!(None, ring.try_pop());
 // push_overwrite adds an element to the buffer, overwriting the oldest element if the buffer is full:
 ring.push_overwrite(10);
 assert_eq!(10, ring.pop());
 assert_eq!(None, ring.try_pop());

Methods

impl<T> AtomicRingQueue<T>[src]

pub fn with_capacity(capacity: usize) -> AtomicRingQueue<T>[src]

Constructs a new empty AtomicRingQueue with the specified capacity the capacity is rounded up to the next power of 2

Examples

 // create an AtomicRingQueue with capacity of 1024 elements
 let ring = ::atomicring::AtomicRingQueue::with_capacity(900);

 // try_pop removes an element of the buffer and returns None if the buffer is empty
 assert_eq!(None, ring.try_pop());
 // push_overwrite adds an element to the buffer, overwriting the oldest element if the buffer is full:
 ring.push_overwrite(10);
 assert_eq!(10, ring.pop());
 assert_eq!(None, ring.try_pop());

pub fn try_push(&self, content: T) -> Result<(), T>[src]

Try to push an object to the atomic ring buffer. If the buffer has no capacity remaining, the pushed object will be returned to the caller as error.

pub fn push_overwrite(&self, content: T)[src]

Pushes an object to the atomic ring buffer. If the buffer is full, another object will be popped to make room for the new object.

pub fn try_pop(&self) -> Option<T>[src]

Pop an object from the ring buffer, returns None if the buffer is empty

pub fn pop(&self) -> T[src]

Pop an object from the ring buffer, waits indefinitely if the buf is empty

pub fn pop_until(&self, deadline: Instant) -> Option<T>[src]

Pop an object from the ring buffer, waiting until the given instant if the buffer is empty. Returns None on timeout

pub fn pop_for(&self, timeout: Duration) -> Option<T>[src]

Pop an object from the ring buffer, waiting until the given instant if the buffer is empty. Returns None on timeout

pub fn len(&self) -> usize[src]

Returns the number of objects stored in the ring buffer that are not in process of being removed.

pub fn is_empty(&self) -> bool[src]

Returns the true if ring buffer is empty. Equivalent to self.len() == 0

pub fn capacity(&self) -> usize[src]

Returns the maximum capacity of the ring buffer. Attention: In fact you can store one element less than the capacity given here

pub fn remaining_cap(&self) -> usize[src]

Returns the remaining capacity of the ring buffer. This is equal to self.cap() - self.len() - pending writes + pending reads.

pub fn clear(&self)[src]

Pop everything from ring buffer and discard it.

Trait Implementations

impl<T: Send> Sync for AtomicRingQueue<T>[src]

Any particular T should never accessed concurrently, so T does not need to be Sync. If T is Send, AtomicRingQueue is Send + Sync

impl<T: Send> Send for AtomicRingQueue<T>[src]

If T is Send, AtomicRingQueue is Send + Sync

impl<T> Debug for AtomicRingQueue<T>[src]

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Erased for T