An circular queue meant for sharing data across threads.
More...
#include <threadsafecircularqueue.h>
|
| template<typename VT > |
| void | push_back (VT &&value) |
| | Add or move an item into the queue. More...
|
| |
| template<typename VT > |
| bool | try_push_back (VT &&value, const std::chrono::milliseconds &wait_duration=std::chrono::milliseconds::zero()) |
| | Add or move an item into the queue. More...
|
| |
| ValueType | pop_front (int *overflows=nullptr, time_t *sent_time=nullptr) |
| | Retrieve an item from the queue. More...
|
| |
| bool | try_pop_front (ValueType *value, int *overflows=nullptr, time_t *sent_time=nullptr, std::chrono::milliseconds wait_duration=std::chrono::milliseconds::zero()) |
| | Retrieve an item from the queue. More...
|
| |
template<typename ValueType, uint32_t capacity>
class ThreadSafeCircularQueue< ValueType, capacity >
An circular queue meant for sharing data across threads.
- Template Parameters
-
| ValueType | Type of objects being passed around. |
| capacity | The maximum capacity of the queue. |
◆ index_type
template<typename ValueType , uint32_t capacity>
◆ value_type
template<typename ValueType , uint32_t capacity>
◆ next()
template<typename ValueType , uint32_t capacity>
Increment an index, wrapping around buffer size.
◆ pop_front()
template<typename ValueType , uint32_t capacity>
| ValueType ThreadSafeCircularQueue< ValueType, capacity >::pop_front |
( |
int * |
overflows = nullptr, |
|
|
time_t * |
sent_time = nullptr |
|
) |
| |
|
inline |
Retrieve an item from the queue.
If the queue is empty, block until an item becomes available.
- Parameters
-
| overflows | If non-null, set to the number of items dropped due to overflow. |
| sent_time | If non-null, the time at which the item was queued. |
- Returns
- The next value from the queue.
◆ push_back()
template<typename ValueType , uint32_t capacity>
template<typename VT >
Add or move an item into the queue.
If the queue is full, wait until there's space.
- Parameters
-
◆ try_pop_front()
template<typename ValueType , uint32_t capacity>
| bool ThreadSafeCircularQueue< ValueType, capacity >::try_pop_front |
( |
ValueType * |
value, |
|
|
int * |
overflows = nullptr, |
|
|
time_t * |
sent_time = nullptr, |
|
|
std::chrono::milliseconds |
wait_duration = std::chrono::milliseconds::zero() |
|
) |
| |
|
inline |
Retrieve an item from the queue.
If the queue is empty, don't block.
- Parameters
-
| value | On return, set to the value retrieved from the queue. |
| overflows | If non-null, set to the number of items dropped due to overflow. |
| sent_time | If non-null, the time at which the item was queued. |
| wait_duration | A duration to wait for for an item; defaults to no wait. |
- Returns
- True if a value was retrieved, false if the queue was empty.
◆ try_push_back()
template<typename ValueType , uint32_t capacity>
template<typename VT >
| bool ThreadSafeCircularQueue< ValueType, capacity >::try_push_back |
( |
VT && |
value, |
|
|
const std::chrono::milliseconds & |
wait_duration = std::chrono::milliseconds::zero() |
|
) |
| |
|
inline |
Add or move an item into the queue.
If the queue is full, mark that an overflow occured, and do not block.
- Parameters
-
| value | The value to add. |
| wait_duration | Optional: If specified, a duration to wait before giving up. Default is to not wait. Observation, however, shows that small waits can go a long way to reduce overflows, providing a chance for readers to catch up when the queue is full. |
- Returns
- True on success, false on overflow.
◆ write_common()
template<typename ValueType , uint32_t capacity>
Perform actions common to the various forms of push_back.
◆ data
template<typename ValueType , uint32_t capacity>
◆ read_bell
template<typename ValueType , uint32_t capacity>
◆ read_index
template<typename ValueType , uint32_t capacity>
◆ read_mutex
template<typename ValueType , uint32_t capacity>
◆ write_bell
template<typename ValueType , uint32_t capacity>
◆ write_index
template<typename ValueType , uint32_t capacity>
◆ write_mutex
template<typename ValueType , uint32_t capacity>
The documentation for this class was generated from the following file: