libmoost
|
#include <threaded_job_scheduler.hpp>
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_t > | jobs_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 |
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.
typedef std::queue<job_t> moost::thread::threaded_job_batch::jobs_t [private] |
Definition at line 119 of file threaded_job_scheduler.hpp.
Definition at line 58 of file threaded_job_scheduler.hpp.
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.
job | The 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
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.
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.
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.
Definition at line 106 of file threaded_job_scheduler.hpp.
void moost::thread::threaded_job_batch::run | ( | worker_group & | wg | ) | [inline] |
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.
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.
Definition at line 194 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.