|
LBANN
0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
|
A queue that is safe for multiple threads to push to or pull from "simultaneously". More...
#include <thread_safe_queue.hpp>
Classes | |
| class | _Node |
| A data value in the thread-safe FIFO queue. More... | |
Public Member Functions | |
| thread_safe_queue () | |
| Default constructor; creates an empty queue. More... | |
| void | push (T value) |
| Adds a value to back of the queue. More... | |
| void | wake_all (bool stop=false) |
| void | set_stop_threads (bool flag) |
| Allow the thread pool to set / reset the flags. More... | |
| std::unique_ptr< T > | try_pop () |
| Try to remove the first value from the queue. More... | |
| std::unique_ptr< T > | wait_and_pop () |
| Wait for data and then return it. More... | |
| bool | empty () const |
| Check if queue is empty. More... | |
Private Member Functions | |
| _Node * | do_get_tail_ () const |
| Get the tail pointer. More... | |
Private Attributes | |
| std::mutex | head_mtx_ |
| The mutex protecting the head of the list. More... | |
| std::mutex | tail_mtx_ |
| The mutex protecting the tail of the list. More... | |
| std::unique_ptr< _Node > | head_ |
| The first node in the list. More... | |
| _Node * | tail_ |
| The last node in the list. More... | |
| std::condition_variable | data_available_ |
| Condition variable tripped when data added. More... | |
| bool | m_stop_threads |
A queue that is safe for multiple threads to push to or pull from "simultaneously".
This version uses locks.
This is essentially a fancy linked-list implementation that enables finer-grained locks than simply wrapping an std::queue. The trade-off is two locks, one for the front and one for the back of the list.
| T | A move- or copy-constructible type |
Definition at line 51 of file thread_safe_queue.hpp.
|
inline |
Default constructor; creates an empty queue.
Definition at line 65 of file thread_safe_queue.hpp.
|
inlineprivate |
Get the tail pointer.
Definition at line 147 of file thread_safe_queue.hpp.
|
inline |
Check if queue is empty.
Definition at line 139 of file thread_safe_queue.hpp.
|
inline |
Adds a value to back of the queue.
Definition at line 70 of file thread_safe_queue.hpp.
|
inline |
Allow the thread pool to set / reset the flags.
Definition at line 98 of file thread_safe_queue.hpp.
|
inline |
Try to remove the first value from the queue.
Definition at line 104 of file thread_safe_queue.hpp.
|
inline |
Wait for data and then return it.
Definition at line 118 of file thread_safe_queue.hpp.
|
inline |
Definition at line 87 of file thread_safe_queue.hpp.
|
private |
Condition variable tripped when data added.
Definition at line 167 of file thread_safe_queue.hpp.
|
private |
The first node in the list.
Definition at line 161 of file thread_safe_queue.hpp.
|
mutableprivate |
The mutex protecting the head of the list.
Definition at line 155 of file thread_safe_queue.hpp.
|
private |
Definition at line 169 of file thread_safe_queue.hpp.
|
private |
The last node in the list.
Definition at line 164 of file thread_safe_queue.hpp.
|
mutableprivate |
The mutex protecting the tail of the list.
Definition at line 158 of file thread_safe_queue.hpp.