9 #ifndef CPPCOMMON_THREADS_SPSC_RING_BUFFER_H
10 #define CPPCOMMON_THREADS_SPSC_RING_BUFFER_H
48 explicit operator bool() const noexcept {
return !
empty(); }
51 bool empty() const noexcept {
return (
size() == 0); }
53 size_t capacity() const noexcept {
return _capacity; }
55 size_t size() const noexcept;
83 typedef
char cache_line_pad[128];
86 const
size_t _capacity;
88 uint8_t* const _buffer;
91 std::atomic<
size_t> _head;
93 std::atomic<
size_t> _tail;
101 #include "spsc_ring_buffer.inl"
Single producer / single consumer wait-free ring buffer.
SPSCRingBuffer(SPSCRingBuffer &&)=delete
SPSCRingBuffer & operator=(const SPSCRingBuffer &)=delete
SPSCRingBuffer(const SPSCRingBuffer &)=delete
bool Enqueue(const void *data, size_t size)
Enqueue a data into the ring buffer (single producer thread method)
SPSCRingBuffer & operator=(SPSCRingBuffer &&)=delete
size_t size() const noexcept
Get ring buffer size in bytes.
bool Dequeue(void *data, size_t &size)
Dequeue a data from the ring buffer (single consumer thread method)
size_t capacity() const noexcept
Get ring buffer capacity in bytes.
bool empty() const noexcept
Is ring buffer empty?
SPSCRingBuffer(size_t capacity)
Default class constructor.
C++ Common project definitions.