Thread safe, blocking queue. More...
#include <blocking_queue.hpp>
Public Member Functions | |
blocking_queue (size_t capacity) | |
Constructor. | |
~blocking_queue ()=default | |
Destructor. | |
void | push (const T &item) |
Insert an item into the queue. | |
void | push (T &&item) |
Insert an item into the queue. | |
bool | try_push (const T &item) |
Try to insert an item into the queue. | |
bool | try_push (T &&item) |
Try to insert an item into the queue. | |
T | pop () |
Retrieve an item from the queue. | |
std::optional< T > | try_pop () |
Try to retrieve an item from the queue. | |
size_t | size () const |
Get the number of items currently in the queue. | |
size_t | capacity () const |
Get the maximum number of items that the queue can hold. | |
Thread safe, blocking queue.
T | Queue items type |
The queue has a fixed capacity (i.e. maximum number of items that can be hold). When the queue is full and a new item is needs to be inserted via blocking_queue::push() the queue blocks until an item is popped. Viceversa, when the queue is empty and an item is required via blocking_queue::pop(), the queue blocks until the first item is pushed.
Definition at line 38 of file blocking_queue.hpp.
|
inlineexplicit |
Constructor.
capacity | set the maximum number of items the queue can hold |
Creates a tc::sdk::blocking_queue instance.
Definition at line 47 of file blocking_queue.hpp.
|
default |
Destructor.
Destructs this.
|
inline |
Insert an item into the queue.
item | The item to be inserted |
If this method is called when the queue is full the calling thread is blocked until an item is popped from the queue.
Definition at line 65 of file blocking_queue.hpp.
|
inline |
Insert an item into the queue.
item | The item to be inserted |
If this method is called when the queue is full the calling thread is blocked until an item is popped from the queue. This is an overload of blocking_queue::push(const T&) which emplaces the item instead of using a const ref.
Definition at line 82 of file blocking_queue.hpp.
|
inline |
Try to insert an item into the queue.
item | The item to be inserted |
If this method is called when the queue is full the calling thread is not blocked and false is returned. Otherwise the thread is locked until the item is inserted, then true is returned.
Definition at line 100 of file blocking_queue.hpp.
|
inline |
Try to insert an item into the queue.
item | The item to be inserted |
If this method is called when the queue is full the calling thread is not blocked and false is returned. Otherwise the thread is locked until the item is inserted, then true is returned. This is an overload of blocking_queue::try_push(const T&) which emplaces the item instead of using a const ref.
Definition at line 121 of file blocking_queue.hpp.
|
inline |
Retrieve an item from the queue.
If this method is called when the queue is full the calling thread is blocked until an item is pushed in the queue.
Definition at line 139 of file blocking_queue.hpp.
|
inline |
Try to retrieve an item from the queue.
If this method is called when the queue is empty the calling thread is not blocked and std::nullopt is returned. Otherwise the thread is locked until the item is removed, then std::optional<T> is returned.
Definition at line 159 of file blocking_queue.hpp.
|
inline |
Get the number of items currently in the queue.
Definition at line 176 of file blocking_queue.hpp.
|
inline |
Get the maximum number of items that the queue can hold.
Definition at line 186 of file blocking_queue.hpp.