|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Pool of consumer threads form a queue. More...
#include <q-consumer-threads.H>
Classes | |
| class | ConsumerQueueEvent |
Public Types | |
| using | Event = ConsumerQueueEvent |
Public Member Functions | |
| ~QueueTheadsPool () | |
| Shut the pool down, as shutdown() does, if it was not, and wait for the events that are running: it threw, which ended the program, and left its threads running on it. | |
| void | create_thread (ConsumerQueueEvent *event) |
Create a thread that consumes the items of the queue with event. | |
| bool | put (T &&item) |
| void | resume () |
| void | suspend () |
| bool | is_suspended () |
| bool | is_shutdown () |
| void | shutdown () |
| Make the threads finish, also those of a suspended pool, and wait for them; again, it waits for the shutdown that another call started. | |
Private Member Functions | |
| void | run_event (ConsumerQueueEvent *event) |
Static Private Member Functions | |
| static void | handler (QueueTheadsPool< T > *threads_pool, ConsumerQueueEvent *event) |
Private Attributes | |
| std::mutex | lck |
| std::condition_variable | cond |
| DynList< ConsumerQueueEvent * > | event_list |
| size_t | num_threads = 0 |
| size_t | num_active = 0 |
| bool | suspended = true |
| bool | shutting_down = false |
| bool | shutdown_done = false |
| std::condition_variable | shutdown_cv |
| DynListQueue< T > | q |
Static Private Attributes | |
| static thread_local const QueueTheadsPool * | running_pool = nullptr |
Pool of consumer threads form a queue.
Definition at line 101 of file q-consumer-threads.H.
| using QueueTheadsPool< T >::Event = ConsumerQueueEvent |
Definition at line 139 of file q-consumer-threads.H.
|
inline |
Shut the pool down, as shutdown() does, if it was not, and wait for the events that are running: it threw, which ended the program, and left its threads running on it.
An event must not destroy its pool.
Definition at line 164 of file q-consumer-threads.H.
|
inline |
Create a thread that consumes the items of the queue with event.
| std::domain_error | if another thread owns event; no thread is created then |
Definition at line 186 of file q-consumer-threads.H.
References ah_domain_error_if, Aleph::DynList< T >::append(), FunctionalMethods< Container, T >::exists(), and Aleph::DynList< T >::remove_ne().
Referenced by main().
|
inlinestaticprivate |
Definition at line 171 of file q-consumer-threads.H.
References QueueTheadsPool< T >::run_event().
|
inline |
Definition at line 258 of file q-consumer-threads.H.
|
inline |
Definition at line 252 of file q-consumer-threads.H.
|
inline |
Definition at line 211 of file q-consumer-threads.H.
References ah_domain_error_if, and Aleph::DynListQueue< T >::put().
Referenced by main().
|
inline |
Definition at line 232 of file q-consumer-threads.H.
Referenced by main().
|
inlineprivate |
Definition at line 289 of file q-consumer-threads.H.
References Aleph::and, QueueTheadsPool< T >::cond, ConsumerQueueEvent< T >::Executing, QueueTheadsPool< T >::lck, QueueTheadsPool< T >::num_active, QueueTheadsPool< T >::num_threads, QueueTheadsPool< T >::q, ConsumerQueueEvent< T >::Ready, QueueTheadsPool< T >::running_pool, QueueTheadsPool< T >::shutdown_cv, QueueTheadsPool< T >::shutting_down, and QueueTheadsPool< T >::suspended.
Referenced by QueueTheadsPool< T >::handler().
|
inline |
Make the threads finish, also those of a suspended pool, and wait for them; again, it waits for the shutdown that another call started.
Called from an event of the pool, it does not wait, as it would for its own thread: the threads finish as their events return. The items still queued are not consumed.
Definition at line 269 of file q-consumer-threads.H.
Referenced by main().
|
inline |
Definition at line 242 of file q-consumer-threads.H.
Referenced by main().
|
private |
Definition at line 144 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().
|
private |
Definition at line 145 of file q-consumer-threads.H.
|
private |
Definition at line 143 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().
|
private |
Definition at line 147 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().
|
private |
Definition at line 146 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().
|
private |
Definition at line 157 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().
|
inlinestaticprivate |
Definition at line 155 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().
|
private |
Definition at line 151 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().
|
private |
Definition at line 150 of file q-consumer-threads.H.
|
private |
Definition at line 149 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().
|
private |
Definition at line 148 of file q-consumer-threads.H.
Referenced by QueueTheadsPool< T >::run_event().