|
Thunderbots Project
|
#include <thread_safe_buffer.hpp>
Public Member Functions | |
| ThreadSafeBuffer (std::size_t buffer_size, bool log_buffer_full=true) | |
| ThreadSafeBuffer (const ThreadSafeBuffer &)=delete | |
| std::optional< T > | popLeastRecentlyAddedValue (Duration max_wait_time=Duration::fromSeconds(0)) |
| std::optional< T > | popMostRecentlyAddedValue (Duration max_wait_time=Duration::fromSeconds(0)) |
| void | push (const T &value) |
| bool | empty () const |
This class represents a buffer of objects
It's public API is fully thread-safe (meaning that it can be accessed by multiple threads at the same time without issue)
| T | The type of whatever is being buffered |
|
explicit |
Creates a new ThreadSafeBuffer
| buffer_size | size of the buffer |
| log_buffer_full | whether or not to log when the buffer is full |
| bool empty | ( | ) | const |
Returns whether or not the buffer is empty
| std::optional< T > popLeastRecentlyAddedValue | ( | Duration | max_wait_time = Duration::fromSeconds(0) | ) |
Removes the value least recently added to the buffer and returns it
ex. if A,B,C were added to the buffer (in that order), this would return A
If the buffer is empty, this function will block until:
| max_wait_time | The maximum duration to wait for a new value before returning |
| std::optional< T > popMostRecentlyAddedValue | ( | Duration | max_wait_time = Duration::fromSeconds(0) | ) |
Removes the value most recently added to the buffer and returns it
ex. if A,B,C were added to the buffer (in that order), this would return C
If the buffer is empty, this function will block until:
| max_wait_time | The maximum duration to wait for a new value before returning |
| void push | ( | const T & | value | ) |
Push the given value onto the buffer
If the buffer is already full, this will overwrite the least recently added value
| value | The value to push onto the buffer |