pub struct AtomicRingQueue<T> { /* private fields */ }
Expand description

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

Implementations§

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

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.

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.

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

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

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

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

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

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

Returns the maximum capacity of the ring buffer

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

Pop everything from ring buffer and discard it.

Trait Implementations§

If T is Send, AtomicRingQueue is Send + Sync

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

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.