JeVois
1.22
JeVois Smart Embedded Machine Vision Toolkit
|
|
#include <jevois/Types/BoundedBuffer.H>
Thread-safe synchronized producer/consumer queue.
BoundedBuffer is designed for use in producer/consumer scenarios where multiple threads wish to push and pop data onto/from the buffer asynchronously. Threads that try to pop data when the buffer is empty will either sleep until data is actually available or get an exception (depending on template args), and threads that try to push data when the buffer is full will either block until some space is available in the buffer or get an exception (depending on template args).
WhenFull | blocking behavior (as jevois::BlockingBehavior) when attempting to push into a full buffer |
WhenEmpty | blocking behavior (as jevois::BlockingBehavior) when attempting to pop from an empty buffer |
Definition at line 37 of file BoundedBuffer.H.
Public Member Functions | |
BoundedBuffer (size_t const siz) | |
Create a new BoundedBuffer with no data and a given size. | |
void | push (T const &val) |
Push a new data element into the buffer, potentially sleeping or throwing if buffer is full, copy version. | |
void | push (T &&val) |
Push a new data element into the buffer, potentially sleeping or throwing if buffer is full, move version. | |
T | pop () |
Pop oldest data element off of the buffer, potentially sleeping until one is available or throwing if empty. | |
size_t | filled_size () const |
Current number of items actually in the buffer. | |
size_t | size () const |
Max (allocated at construction) size of the buffer. | |
void | clear () |
Clear all contents, resetting filled_size() to zero (size() remains unchanged at the max possible size) | |
jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::BoundedBuffer | ( | size_t const | siz | ) |
Create a new BoundedBuffer with no data and a given size.
void jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::clear | ( | ) |
Clear all contents, resetting filled_size() to zero (size() remains unchanged at the max possible size)
size_t jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::filled_size | ( | ) | const |
Current number of items actually in the buffer.
This function is mostly provided for informational messages and beware that the actual filled size may change in a multithreaded environment between the time we return here and the time the caller tries to use the result.
T jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::pop | ( | ) |
Pop oldest data element off of the buffer, potentially sleeping until one is available or throwing if empty.
void jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::push | ( | T && | val | ) |
Push a new data element into the buffer, potentially sleeping or throwing if buffer is full, move version.
void jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::push | ( | T const & | val | ) |
Push a new data element into the buffer, potentially sleeping or throwing if buffer is full, copy version.
size_t jevois::BoundedBuffer< T, WhenFull, WhenEmpty >::size | ( | ) | const |
Max (allocated at construction) size of the buffer.