libmoost
|
#include <worker_group.hpp>
Public Types | |
typedef boost::function0< void > | job_t |
Public Member Functions | |
worker_group (size_t num_workers=1) | |
~worker_group () | |
void | stop () |
bool | running () const |
bool | add_job (job_t job) |
size_t | size () const |
size_t | queued_jobs () const |
Private Types | |
typedef std::queue< job_t > | jobs_t |
Private Member Functions | |
void | work () |
Private Attributes | |
boost::thread_group | m_workers |
jobs_t | m_jobs |
boost::condition_variable | m_cond |
boost::mutex | m_mx |
volatile sig_atomic_t | m_running |
A group of worker threads
This is an easy to use, multithreaded work dispatcher. You can add jobs at any time and they will be dispatched to the next available worker thread.
Definition at line 49 of file worker_group.hpp.
typedef boost::function0<void> moost::thread::worker_group::job_t |
Definition at line 52 of file worker_group.hpp.
typedef std::queue<job_t> moost::thread::worker_group::jobs_t [private] |
Definition at line 157 of file worker_group.hpp.
moost::thread::worker_group::worker_group | ( | size_t | num_workers = 1 | ) | [inline, explicit] |
Create a worker group
num_workers | Number of worker threads. |
Definition at line 59 of file worker_group.hpp.
moost::thread::worker_group::~worker_group | ( | ) | [inline] |
Stop and destroy a worker group
Definition at line 76 of file worker_group.hpp.
bool moost::thread::worker_group::add_job | ( | job_t | job | ) | [inline] |
Add a new job to the worker group
The new job will be dispatched to the first available worker thread.
job | The job to add to the dispatcher. |
Definition at line 118 of file worker_group.hpp.
size_t moost::thread::worker_group::queued_jobs | ( | ) | const [inline] |
Return the number of queued jobs
Definition at line 150 of file worker_group.hpp.
bool moost::thread::worker_group::running | ( | ) | const [inline] |
Check whether the worker group is still running
Definition at line 106 of file worker_group.hpp.
size_t moost::thread::worker_group::size | ( | ) | const [inline] |
Return the number of worker threads
Definition at line 140 of file worker_group.hpp.
void moost::thread::worker_group::stop | ( | ) | [inline] |
Stop a worker group
Definition at line 90 of file worker_group.hpp.
void moost::thread::worker_group::work | ( | ) | [inline, private] |
boost::condition_variable moost::thread::worker_group::m_cond [private] |
Definition at line 191 of file worker_group.hpp.
jobs_t moost::thread::worker_group::m_jobs [private] |
Definition at line 190 of file worker_group.hpp.
boost::mutex moost::thread::worker_group::m_mx [mutable, private] |
Definition at line 192 of file worker_group.hpp.
volatile sig_atomic_t moost::thread::worker_group::m_running [private] |
Definition at line 193 of file worker_group.hpp.
boost::thread_group moost::thread::worker_group::m_workers [private] |
Definition at line 189 of file worker_group.hpp.