MPD
0.20.18
|
A WorkQueue manages the synchronisation around a queue of work items, where a number of client threads queue tasks and a number of worker threads take and execute them. More...
#include <WorkQueue.hxx>
Public Member Functions | |
WorkQueue (const char *_name) | |
Create a WorkQueue. More... | |
~WorkQueue () | |
WorkQueue (const WorkQueue &)=delete | |
WorkQueue & | operator= (const WorkQueue &)=delete |
bool | start (unsigned nworkers, void *(*workproc)(void *), void *arg) |
Start the worker threads. More... | |
template<typename U > | |
bool | put (U &&u) |
Add item to work queue, called from client. More... | |
void | setTerminateAndWait () |
Tell the workers to exit, and wait for them. More... | |
bool | take (T &tp) |
Take task from queue. More... | |
void | workerExit () |
Advertise exit and abort queue. More... | |
A WorkQueue manages the synchronisation around a queue of work items, where a number of client threads queue tasks and a number of worker threads take and execute them.
The goal is to introduce some level of parallelism between the successive steps of a previously single threaded pipeline. For example data extraction / data preparation / index update, but this could have other uses.
There is no individual task status return. In case of fatal error, the client or worker sets an end condition on the queue. A second queue could conceivably be used for returning individual task status.
Definition at line 49 of file WorkQueue.hxx.
Create a WorkQueue.
_name | for message printing |
Definition at line 71 of file WorkQueue.hxx.
Definition at line 76 of file WorkQueue.hxx.
Add item to work queue, called from client.
Sleeps if there are already too many.
Definition at line 121 of file WorkQueue.hxx.
|
inline |
Tell the workers to exit, and wait for them.
Definition at line 136 of file WorkQueue.hxx.
|
inline |
Start the worker threads.
nworkers | number of threads copies to start. |
workproc | thread function. It should loop taking (QueueWorker::take()) and executing tasks. |
arg | initial parameter to thread function. |
Definition at line 91 of file WorkQueue.hxx.
|
inline |
Take task from queue.
Called from worker.
Sleeps if there are not enough. Signal if we go to sleep on empty queue: client may be waiting for our going idle.
Definition at line 167 of file WorkQueue.hxx.
|
inline |
Advertise exit and abort queue.
Called from worker
This would happen after an unrecoverable error, or when the queue is terminated by the client. Workers never exit normally, except when the queue is shut down (at which point ok is set to false by the shutdown code anyway). The thread must return/exit immediately after calling this.
Definition at line 193 of file WorkQueue.hxx.