|
| thread_queue () |
|
| thread_queue (size_t cap) |
|
bool | empty () const |
|
size_type | capacity () const |
|
void | capacity (size_type cap) |
|
size_type | size () const |
|
void | put (value_type val) |
|
bool | try_put (value_type val) |
|
template<typename Rep , class Period > |
bool | try_put_for (value_type val, const std::chrono::duration< Rep, Period > &relTime) |
|
template<class Clock , class Duration > |
bool | try_put_until (value_type val, const std::chrono::time_point< Clock, Duration > &absTime) |
|
void | get (value_type *val) |
|
value_type | get () |
|
bool | try_get (value_type *val) |
|
template<typename Rep , class Period > |
bool | try_get_for (value_type *val, const std::chrono::duration< Rep, Period > &relTime) |
|
template<class Clock , class Duration > |
bool | try_get_until (value_type *val, const std::chrono::time_point< Clock, Duration > &absTime) |
|
template<typename T, class Container = std::deque<T>>
class mqtt::thread_queue< T, Container >
A thread-safe queue for inter-thread communication.
This is a locking queue with blocking operations. The get() operations can always block on an empty queue, but have variations for non-blocking (try_get) and bounded-time blocking (try_get_for, try_get_until).
- The default queue has a capacity that is unbounded in the practical sense, limited by available memory. In this mode the object will not block when placing values into the queue. A capacity can bet set with the constructor or, at any time later by calling the capacity(size_type) method. Using this latter method, the capacity can be set to an amount smaller than the current size of the queue. In that case all put's to the queue will block until the number of items are removed from the queue to bring the size below the new capacity.
- Note that the queue uses move semantics to place items into the queue and remove items from the queue. This means that the type, T, of the data held by the queue only needs to follow move semantics; not copy semantics. In addition, this means that copies of the value will not be left in the queue. This is especially useful when creating queues of shared pointers, as the "dead" part of the queue will not hold onto a reference count after the item has been removed from the queue.
- Parameters
-
T | The type of the items to be held in the queue. |
Container | The type of the underlying container to use. It must support back(), front(), push_back(), pop_front(). |
template<typename T , class Container = std::deque<T>>
template<typename Rep , class Period >
Attempt to place an item in the queue with a bounded wait. This will attempt to place the value in the queue, but if it is full, it will wait up to the specified time duration before timing out.
- Parameters
-
val | The value to add to the queue. |
relTime | The amount of time to wait until timing out. |
- Returns
- true if the value was added to the queue, false if a timeout occurred.
template<typename T , class Container = std::deque<T>>
template<class Clock , class Duration >
Attempt to place an item in the queue with a bounded wait to an absolute time point. This will attempt to place the value in the queue, but if it is full, it will wait up until the specified time before timing out.
- Parameters
-
val | The value to add to the queue. |
absTime | The absolute time to wait to before timing out. |
- Returns
- true if the value was added to the queue, false if a timeout occurred.
template<typename T , class Container = std::deque<T>>
template<typename Rep , class Period >
Attempt to remove an item from the queue for a bounded amount of time. This will retrieve the next item from the queue. If the queue is empty, it will wait the specified amount of time for an item to arrive before timing out.
- Parameters
-
val | Pointer to a variable to receive the value. |
relTime | The amount of time to wait until timing out. |
- Returns
- true if the value was removed the queue, false if a timeout occurred.
template<typename T , class Container = std::deque<T>>
template<class Clock , class Duration >
Attempt to remove an item from the queue for a bounded amount of time. This will retrieve the next item from the queue. If the queue is empty, it will wait until the specified time for an item to arrive before timing out.
- Parameters
-
val | Pointer to a variable to receive the value. |
absTime | The absolute time to wait to before timing out. |
- Returns
- true if the value was removed from the queue, false if a timeout occurred.