libmoost
moost::thread::worker_group Class Reference

#include <worker_group.hpp>

Inheritance diagram for moost::thread::worker_group:
Collaboration diagram for moost::thread::worker_group:

List of all members.

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_tjobs_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

Detailed Description

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.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

moost::thread::worker_group::worker_group ( size_t  num_workers = 1) [inline, explicit]

Create a worker group

Parameters:
num_workersNumber of worker threads.

Definition at line 59 of file worker_group.hpp.

Here is the call graph for this function:

Stop and destroy a worker group

Definition at line 76 of file worker_group.hpp.

Here is the call graph for this function:


Member Function Documentation

Add a new job to the worker group

The new job will be dispatched to the first available worker thread.

Parameters:
jobThe job to add to the dispatcher.

Definition at line 118 of file worker_group.hpp.

Here is the caller graph for this function:

size_t moost::thread::worker_group::queued_jobs ( ) const [inline]

Return the number of queued jobs

Returns:
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

Returns:
The number of worker threads.

Definition at line 140 of file worker_group.hpp.

Stop a worker group

Definition at line 90 of file worker_group.hpp.

Here is the caller graph for this function:

void moost::thread::worker_group::work ( ) [inline, private]

Definition at line 159 of file worker_group.hpp.

Here is the caller graph for this function:


Member Data Documentation

boost::condition_variable moost::thread::worker_group::m_cond [private]

Definition at line 191 of file worker_group.hpp.

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.


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