A thread-safe blocking concurrent queue. More...
#include <blocking_queue.h>
Public Member Functions | |
| void | push (T &&item) |
| Pushes a new item to the queue, under a lock. More... | |
| cl::api_status | pop (T *next) |
| Pops an item from the queue. More... | |
| size_t | workload_count () const |
| Returns the current workload count. More... | |
| void | close () |
| close the queue More... | |
A thread-safe blocking concurrent queue.
The queue will acquire a mutex internally while pushing to it, and likewise while popping (hence, no synchronization needs to happen when pushing/popping to the queue itself).
Popping values from the queue will block the thread it's running on if the queue is empty. The queue is unbounded in terms of how many items can be pushed to it.
| T | The type of work objects this queue holds |
|
inline |
close the queue
This essentially marks the queue as consumed/done and it will stop processing values. If a thread is waiting on a pop(), it will be unblocked and flagged to return without producing a result.
|
inline |
Pops an item from the queue.
If the queue is empty, this function will block the calling thread. The thread will only wake up if from this state if:
| next | A pointer that will hold the next item on success |
|
inline |
Pushes a new item to the queue, under a lock.
| item | The item to push to the queue |
|
inline |
Returns the current workload count.