![]() |
PosturePerfection
|
A synchronising buffer to be used as a communication mechanism between threads. More...
#include <pipeline.h>
Public Member Functions | |
Buffer (bool *running_ptr, size_t max_size) | |
Construct a new Buffer object. More... | |
void | push (T frame) |
Push a frame to the queue. More... | |
bool | try_push (T frame) |
Push a frame to the queue (doesn't block if queue is full) More... | |
PopResult< T > | pop () |
Pop the oldest element in the queue and return it. More... | |
A synchronising buffer to be used as a communication mechanism between threads.
The buffer ensures that elements are in order based on the element's id
field. Attempting to push
an element that is not next in line will block until the missing element has been pushed by a different thread. An object of this class may therefore be used to share the load at any stage in a pipeline between multiple threads without needing to worry about issues in the order of elements.
It is implemented as a circular buffer.
T | The type for elements in the buffer. This must provide an id field that is a uint8_t . |
|
inlineexplicit |
Construct a new Buffer
object.
running_ptr | Pointer to the Pipeline::Pipeline::running flag |
max_size | Maximum desired useable size of underlying memory |
|
inline |
Pop the oldest element in the queue and return it.
PopResult<T>
Oldest frame on the queue. Note: the valid
flag of the result must be checked before use.
|
inline |
Push a frame to the queue.
This blocks if the frame's ID is not the next in the series, until the missing frame has been pushed by another thread. Also blocks if the maximum size is reached, until elements are popped.
frame | Frame to be pushed to the queue |
|
inline |
Push a frame to the queue (doesn't block if queue is full)
This blocks if the frame's ID is not the next in the series, until the missing frame has been pushed by another thread. It returns if the queue is full.
frame | Frame to be pushed to the queue |
true
If pushing was successful false
If the frame was not pushed, i.e., the queue was full; or the pipeline is halting