|
cds
2.3.2
|
Single-producer single-consumer ring buffer. More...
#include <cds/container/weak_ringbuffer.h>
Data Structures | |
| struct | rebind |
| Rebind template arguments. More... | |
Public Types | |
| typedef T | value_type |
| Value type to be stored in the ring buffer. | |
| typedef Traits | traits |
| Ring buffer traits. | |
| typedef traits::memory_model | memory_model |
Memory ordering. See cds::opt::memory_model option. | |
| typedef traits::value_cleaner | value_cleaner |
Value cleaner, see weak_ringbuffer::traits::value_cleaner. | |
Public Member Functions | |
| WeakRingBuffer (size_t capacity=0) | |
Creates the ring buffer of capacity. More... | |
| ~WeakRingBuffer () | |
| Destroys the ring buffer. | |
| template<typename Q , typename CopyFunc > | |
| bool | push (Q *arr, size_t count, CopyFunc copy) |
Batch push - push array arr of size count. More... | |
| template<typename Q > | |
| std::enable_if< std::is_constructible< value_type, Q >::value, bool >::type | push (Q *arr, size_t count) |
Batch push - push array arr of size count with assignment as copy functor. More... | |
| template<typename... Args> | |
| std::enable_if< std::is_constructible< value_type, Args... >::value, bool >::type | emplace (Args &&... args) |
Push one element created from args. More... | |
| template<typename Func > | |
| bool | enqueue_with (Func f) |
| Enqueues data to the ring using a functor. More... | |
| bool | enqueue (value_type const &val) |
Enqueues val value into the queue. More... | |
| bool | enqueue (value_type &&val) |
Enqueues val value into the queue, move semantics. | |
| bool | push (value_type const &val) |
Synonym for enqueue( value_type const& ) | |
| bool | push (value_type &&val) |
Synonym for enqueue( value_type&& ) | |
| template<typename Func > | |
| bool | push_with (Func f) |
Synonym for enqueue_with() | |
| template<typename Q , typename CopyFunc > | |
| bool | pop (Q *arr, size_t count, CopyFunc copy) |
Batch pop count element from the ring buffer into arr. More... | |
| template<typename Q > | |
| std::enable_if< std::is_assignable< Q &, value_type const & >::value, bool >::type | pop (Q *arr, size_t count) |
Batch pop - push array arr of size count with assignment as copy functor. More... | |
| template<typename Q > | |
| std::enable_if< std::is_assignable< Q &, value_type const & >::value, bool >::type | dequeue (Q &val) |
Dequeues an element from the ring to val. More... | |
| template<typename Q > | |
| std::enable_if< std::is_assignable< Q &, value_type const & >::value, bool >::type | pop (Q &val) |
Synonym for dequeue( Q& ) | |
| template<typename Func > | |
| bool | dequeue_with (Func f) |
| Dequeues a value using a functor. More... | |
| template<typename Func > | |
| bool | pop_with (Func f) |
Synonym for dequeue_with() | |
| value_type * | front () |
| Gets pointer to first element of ring buffer. More... | |
| bool | pop_front () |
| Removes front element of ring-buffer. More... | |
| void | clear () |
| Clears the ring buffer (only consumer can call this function!) | |
| bool | empty () const |
| Checks if the ring-buffer is empty. | |
| bool | full () const |
| Checks if the ring-buffer is full. | |
| size_t | size () const |
| Returns the current size of ring buffer. | |
| size_t | capacity () const |
| Returns capacity of the ring buffer. | |
Single-producer single-consumer ring buffer.
Source: [2013] Nhat Minh Le, Adrien Guatto, Albert Cohen, Antoniu Pop. Correct and Effcient Bounded FIFO Queues. [Research Report] RR-8365, INRIA. 2013. <hal-00862450>
Ring buffer is a bounded queue. Additionally, WeakRingBuffer supports batch operations - you can push/pop an array of elements.
There are a specialization WeakRingBuffer<void, Traits> that is not a queue but a "memory pool" between producer and consumer threads. WeakRingBuffer<void> supports variable-sized data.
WeakRingBuffer is developed for 64-bit architecture. 32-bit platform must provide support for 64-bit atomics.
|
inline |
Creates the ring buffer of capacity.
For cds::opt::v::uninitialized_static_buffer the nCapacity parameter is ignored.
If the buffer capacity is a power of two, lightweight binary arithmetics is used instead of modulo arithmetics.
|
inline |
Dequeues an element from the ring to val.
The function is available only if std::is_assignable<Q&, value_type const&>::value is true.
Returns false if the ring is full or true otherwise.
|
inline |
Dequeues a value using a functor.
Func is a functor called to copy dequeued value. The functor takes one argument - a reference to removed node:
Returns true if the ring is not empty, false otherwise. The functor is called only if the ring is not empty.
|
inline |
Push one element created from args.
The function is available only if std::is_constructible<value_type, Args...>::value is true.
Returns false if the ring is full or true otherwise.
|
inline |
Enqueues val value into the queue.
The new queue item is created by calling placement new in free cell. Returns true if success, false if the ring is full.
|
inline |
Enqueues data to the ring using a functor.
Func is a functor called to copy a value to the ring element. The functor f takes one argument - a reference to a empty cell of type value_type :
|
inline |
Gets pointer to first element of ring buffer.
If the ring buffer is empty, returns nullptr
The function is thread-safe since there is only one consumer. Recall, WeakRingBuffer is single-producer/single consumer container.
|
inline |
Batch pop count element from the ring buffer into arr.
CopyFunc is a per-element copy functor: for each element of arr copy( arr[i], source ) is called. The CopyFunc signature:
Returns true if success or false if not enough space in the ring
|
inline |
Batch pop - push array arr of size count with assignment as copy functor.
This function is equivalent for:
The function is available only if std::is_assignable<Q&, value_type const&>::value is true.
Returns true if success or false if not enough space in the ring
|
inline |
Removes front element of ring-buffer.
If the ring-buffer is empty, returns false. Otherwise, pops the first element from the ring.
|
inline |
Batch push - push array arr of size count.
CopyFunc is a per-element copy functor: for each element of arr copy( dest, arr[i] ) is called. The CopyFunc signature:
Here element is uninitialized so you should construct it using placement new if needed; for example, if the element type is str::string and Q is char const*, copy functor can be:
You may use move semantics if appropriate:
Returns true if success or false if not enough space in the ring
|
inline |
Batch push - push array arr of size count with assignment as copy functor.
This function is equivalent for:
The function is available only if std::is_constructible<value_type, Q>::value is true.
Returns true if success or false if not enough space in the ring