libmoost
moost::thread::threaded_job_batch Class Reference

#include <threaded_job_scheduler.hpp>

Inheritance diagram for moost::thread::threaded_job_batch:
Collaboration diagram for moost::thread::threaded_job_batch:

List of all members.

Public Member Functions

 threaded_job_batch ()
virtual void add (job_t job)
void run (worker_group &wg)
size_t count () const
const std::vector< std::string > & errors () const

Private Types

typedef std::queue< job_tjobs_t

Private Member Functions

void do_one (worker_group &wg)
bool done () const
void run_one (job_t &job)

Private Attributes

jobs_t m_jobs
boost::condition_variable m_cond
boost::mutex m_mx
volatile size_t m_todo
volatile size_t m_count
std::vector< std::string > m_errors
boost::mutex m_mx_errors

Detailed Description

A job batch that runs jobs in a set of worker threads

This implementation of a job_batch runs jobs in a set of worker threads provided by the threaded_job_scheduler class.

Definition at line 53 of file threaded_job_scheduler.hpp.


Member Typedef Documentation

typedef std::queue<job_t> moost::thread::threaded_job_batch::jobs_t [private]

Definition at line 119 of file threaded_job_scheduler.hpp.


Constructor & Destructor Documentation


Member Function Documentation

virtual void moost::thread::threaded_job_batch::add ( job_t  job) [inline, virtual]

Add a new job to the batch

This method adds a job to the concrete implementation. When this job gets run is determined by the implementation. However, new jobs may be added even while jobs from the current batch are being run as long as the batch doesn't run out of jobs. In particular, this means that it's always safe to add new jobs from within jobs of the current batch.

Parameters:
jobThe job to be added.

Implements moost::thread::job_batch.

Definition at line 64 of file threaded_job_scheduler.hpp.

size_t moost::thread::threaded_job_batch::count ( ) const [inline]

Get the number of jobs executed in this batch

Returns:
The total number of jobs.

Definition at line 88 of file threaded_job_scheduler.hpp.

void moost::thread::threaded_job_batch::do_one ( worker_group wg) [inline, private]

Enqueue one job to worker threads

This method is supposed to be called by threaded_job_scheduler only. It pops the next job off the job queue and enqueues it to run in the next available worker thread.

Definition at line 128 of file threaded_job_scheduler.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool moost::thread::threaded_job_batch::done ( ) const [inline, private]

Check if all jobs are done

This method is supposed to be called by threaded_job_scheduler only. Does more or less what it says on the tin, though it'll block if the job queue is empty. This is to ensure that new jobs can still be added while other jobs are being run.

Definition at line 150 of file threaded_job_scheduler.hpp.

Here is the caller graph for this function:

const std::vector<std::string>& moost::thread::threaded_job_batch::errors ( ) const [inline]

Get errors that have been caught

Get all errors that have been caught while running the jobs in this batch.

This method is only safe to call after all jobs in this batch have completed. It will throw if there are any unprocessed jobs in the batch.

Returns:
A vector of error strings.

Definition at line 106 of file threaded_job_scheduler.hpp.

Definition at line 75 of file threaded_job_scheduler.hpp.

Here is the call graph for this function:

void moost::thread::threaded_job_batch::run_one ( job_t job) [inline, private]

Runs a single job

This method runs in the various worker threads provided by the scheduler.

Definition at line 168 of file threaded_job_scheduler.hpp.

Here is the caller graph for this function:


Member Data Documentation

boost::condition_variable moost::thread::threaded_job_batch::m_cond [mutable, private]

Definition at line 195 of file threaded_job_scheduler.hpp.

volatile size_t moost::thread::threaded_job_batch::m_count [private]

Definition at line 198 of file threaded_job_scheduler.hpp.

std::vector<std::string> moost::thread::threaded_job_batch::m_errors [private]

Definition at line 199 of file threaded_job_scheduler.hpp.

boost::mutex moost::thread::threaded_job_batch::m_mx [mutable, private]

Definition at line 196 of file threaded_job_scheduler.hpp.

boost::mutex moost::thread::threaded_job_batch::m_mx_errors [mutable, private]

Definition at line 200 of file threaded_job_scheduler.hpp.

volatile size_t moost::thread::threaded_job_batch::m_todo [private]

Definition at line 197 of file threaded_job_scheduler.hpp.


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