Struct atomicring::AtomicRingQueue [] [src]

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]

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

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

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

Returns the maximum capacity of the ring buffer

[src]

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

[src]

Pop everything from ring buffer and discard it.

Trait Implementations

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

If T is Send, AtomicRingQueue is Send + Sync

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