Realtime-safe single-reader multi-writer queue (aka lock-free ringbuffer). More...
#include <SRMWQueue.hpp>
Public Member Functions | |
SRMWQueue (size_t size) | |
size_t | capacity () const |
bool | full () const |
Return whether the queue is full. | |
bool | push (const T &obj) |
Push an item onto the back of the SRMWQueue - realtime-safe, not thread-safe. | |
bool | empty () const |
Return whether the queue is empty. | |
T & | front () const |
Return the element at the front of the queue without removing it. | |
void | pop () |
Pop an item off the front of the queue - realtime-safe, NOT thread-safe. |
Realtime-safe single-reader multi-writer queue (aka lock-free ringbuffer).
Implemented as a dequeue in a fixed array. Both push and pop are realtime safe, but only push is threadsafe. In other words, multiple threads can push data into this queue for a single thread to consume.
The interface is intentionally as similar to std::queue as possible, but note the additional thread restrictions imposed (e.g. empty() is only legal to call in the read thread).
Obey the threading restrictions documented here, or horrible nasty (possibly undetected) errors will occur.
If you only need a single writer, use SRSWQueue. This is slightly more computationally expensive, and allocates an additional size words of memory (ie if you're using this for ints or pointers etc, SRMWQueue will be twice the size of SRSWQueue for the same queue size. Additionally, the size of this queue must be a power of 2 (SRSWQueue does not have this limitation).
bool Raul::SRMWQueue< T >::full | ( | ) | const [inline] |
Return whether the queue is full.
Write thread(s) only.
bool Raul::SRMWQueue< T >::push | ( | const T & | elem | ) | [inline] |
Push an item onto the back of the SRMWQueue - realtime-safe, not thread-safe.
Write thread(s) only.
References Raul::AtomicInt::exchange_and_add().
bool Raul::SRMWQueue< T >::empty | ( | ) | const [inline] |
Return whether the queue is empty.
Read thread only.
T & Raul::SRMWQueue< T >::front | ( | ) | const [inline] |
Return the element at the front of the queue without removing it.
It is a fatal error to call front() when the queue is empty. Read thread only.
void Raul::SRMWQueue< T >::pop | ( | ) | [inline] |
Pop an item off the front of the queue - realtime-safe, NOT thread-safe.
It is a fatal error to call pop() if the queue is empty. Read thread only.