|
cds
2.3.2
|
Single-producer single-consumer ring buffer for untyped variable-sized data. More...
#include <cds/container/weak_ringbuffer.h>
Public Types | |
| typedef Traits | traits |
| Ring buffer traits. | |
| typedef traits::memory_model | memory_model |
Memory ordering. See cds::opt::memory_model option. | |
Public Member Functions | |
| WeakRingBuffer (size_t capacity=0) | |
Creates the ring buffer of capacity bytes. More... | |
| void * | back (size_t size) |
[producer] Reserve size bytes More... | |
| void | push_back () |
| [producer] Push reserved bytes into ring More... | |
| bool | push_back (void const *data, size_t size) |
[producer] Push data of size bytes into ring More... | |
| std::pair< void *, size_t > | front () |
| [consumer] Get top data from the ring More... | |
| bool | pop_front () |
| [consumer] Pops top data More... | |
| void | clear () |
| [consumer] Clears the ring buffer | |
| 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 for untyped variable-sized data.
This SPSC ring-buffer is intended for data of variable size. The producer allocates a buffer from ring, you fill it with data and pushes them back to ring. The consumer thread reads data from front-end and then pops them:
WeakRingBuffer is developed for 64-bit architecture. 32-bit platform must provide support for 64-bit atomics.
|
inline |
Creates the ring buffer of capacity bytes.
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 |
[producer] Reserve size bytes
The function returns a pointer to reserved buffer of size bytes. If no enough space in the ring buffer the function returns nullptr.
After successful back() you should fill the buffer provided and call push_back():
|
inline |
[consumer] Get top data from the ring
If the ring is empty, the function returns nullptr in std:pair::first.
|
inline |
[consumer] Pops top data
Typical consumer workloop:
|
inline |
[producer] Push reserved bytes into ring
The function pushes reserved buffer into the ring. Afte this call, the buffer becomes visible by a consumer:
|
inline |
[producer] Push data of size bytes into ring
This function invokes back( size ), memcpy( buf, data, size ) and push_back() in one call.