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]
pub fn with_capacity(capacity: usize) -> AtomicRingQueue<T>
[src]
Constructs a new empty AtomicRingQueue
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 size(&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.size() == 0
pub fn cap(&self) -> usize
[src]
Returns the maximum capacity of the ring buffer
pub fn remaining_cap(&self) -> usize
[src]
Returns the remaining capacity of the ring buffer.
This is equal to self.cap() - self.size() - pending writes + pending reads
.
pub fn clear(&self)
[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