Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
QueueTheadsPool< T > Class Template Reference

Pool of consumer threads form a queue. More...

#include <q-consumer-threads.H>

Collaboration diagram for QueueTheadsPool< T >:
[legend]

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
 

Detailed Description

template<typename T>
class QueueTheadsPool< T >

Pool of consumer threads form a queue.

Deprecated:
It goes in 8.0.0: use ThreadPool (thread_pool.H).

Definition at line 101 of file q-consumer-threads.H.

Member Typedef Documentation

◆ Event

template<typename T >
using QueueTheadsPool< T >::Event = ConsumerQueueEvent

Definition at line 139 of file q-consumer-threads.H.

Constructor & Destructor Documentation

◆ ~QueueTheadsPool()

template<typename T >
QueueTheadsPool< T >::~QueueTheadsPool ( )
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.

Member Function Documentation

◆ create_thread()

template<typename T >
void QueueTheadsPool< T >::create_thread ( ConsumerQueueEvent *  event)
inline

Create a thread that consumes the items of the queue with event.

Exceptions
std::domain_errorif 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().

◆ handler()

template<typename T >
static void QueueTheadsPool< T >::handler ( QueueTheadsPool< T > *  threads_pool,
ConsumerQueueEvent *  event 
)
inlinestaticprivate

Definition at line 171 of file q-consumer-threads.H.

References QueueTheadsPool< T >::run_event().

◆ is_shutdown()

template<typename T >
bool QueueTheadsPool< T >::is_shutdown ( )
inline

Definition at line 258 of file q-consumer-threads.H.

◆ is_suspended()

template<typename T >
bool QueueTheadsPool< T >::is_suspended ( )
inline

Definition at line 252 of file q-consumer-threads.H.

◆ put()

template<typename T >
bool QueueTheadsPool< T >::put ( T &&  item)
inline

Definition at line 211 of file q-consumer-threads.H.

References ah_domain_error_if, and Aleph::DynListQueue< T >::put().

Referenced by main().

◆ resume()

template<typename T >
void QueueTheadsPool< T >::resume ( )
inline

Definition at line 232 of file q-consumer-threads.H.

Referenced by main().

◆ run_event()

◆ shutdown()

template<typename T >
void QueueTheadsPool< T >::shutdown ( )
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().

◆ suspend()

template<typename T >
void QueueTheadsPool< T >::suspend ( )
inline

Definition at line 242 of file q-consumer-threads.H.

Referenced by main().

Member Data Documentation

◆ cond

template<typename T >
std::condition_variable QueueTheadsPool< T >::cond
private

Definition at line 144 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().

◆ event_list

template<typename T >
DynList<ConsumerQueueEvent*> QueueTheadsPool< T >::event_list
private

Definition at line 145 of file q-consumer-threads.H.

◆ lck

template<typename T >
std::mutex QueueTheadsPool< T >::lck
private

Definition at line 143 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().

◆ num_active

template<typename T >
size_t QueueTheadsPool< T >::num_active = 0
private

Definition at line 147 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().

◆ num_threads

template<typename T >
size_t QueueTheadsPool< T >::num_threads = 0
private

Definition at line 146 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().

◆ q

template<typename T >
DynListQueue<T> QueueTheadsPool< T >::q
private

Definition at line 157 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().

◆ running_pool

template<typename T >
thread_local const QueueTheadsPool* QueueTheadsPool< T >::running_pool = nullptr
inlinestaticprivate

Definition at line 155 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().

◆ shutdown_cv

template<typename T >
std::condition_variable QueueTheadsPool< T >::shutdown_cv
private

Definition at line 151 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().

◆ shutdown_done

template<typename T >
bool QueueTheadsPool< T >::shutdown_done = false
private

Definition at line 150 of file q-consumer-threads.H.

◆ shutting_down

template<typename T >
bool QueueTheadsPool< T >::shutting_down = false
private

Definition at line 149 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().

◆ suspended

template<typename T >
bool QueueTheadsPool< T >::suspended = true
private

Definition at line 148 of file q-consumer-threads.H.

Referenced by QueueTheadsPool< T >::run_event().


The documentation for this class was generated from the following file: