#include <WorkerGroup.h>
Inheritance diagram for SctService::WorkerGroup< T >:
Queue @{ the queue itself contains pointers to objects to be | |
worked on. | |
void | addTime (double t) |
timer watch | |
std::queue< DataType > | m_queue |
timer watch | |
boost::thread_group | m_thread_group |
boost thread group from which threads can be created | |
volatile bool | m_run |
if false, threads are to stop. | |
volatile bool | m_pause |
does not execute work() if true | |
volatile unsigned | m_sleeptime |
time to sleep if queue is empty | |
std::string | m_reportTo |
name to report to IS | |
volatile int | m_reportInterval |
name to report to IS | |
boost::mutex | m_queueAccess |
queueLock | |
boost::mutex | m_vectorAccess |
vectorOfWorkersLock | |
boost::recursive_mutex | m_reportAccess |
vectorOfWorkersLock | |
volatile unsigned long | m_nDone |
count of number of jobs done | |
volatile double | m_time |
time taken working | |
class | Worker |
timer watch | |
class | Reporter |
timer watch | |
Public Types | |
typedef T | DataType |
Public Member Functions | |
void | go (unsigned nWorker=1) |
Start this worker group. the number of worker threads to be started. | |
unsigned | queueSize () const |
get the number of objects in the queue | |
unsigned | nWorkers () const |
get the number of workers in the map | |
unsigned long | nDone () const |
get the number of jobs done | |
unsigned | busy () const |
get the number of threads which are busy. | |
void | stop () |
Raise flag to stop all worker threads. | |
void | setPaused (bool paused=true) |
void | join () |
Call this to make sure that Worker threads continue to completion. | |
unsigned | paused () const |
get the number of paused threads | |
void | setSleepTime (unsigned msec) |
Set sleep time for all workers, if no items are on the queue. | |
unsigned | getSleepTime () const |
Get the sleep time. | |
DataType | pop () |
void | push (DataType ob) |
Push an object onto the back of the queue. | |
virtual | ~WorkerGroup () |
destructor | |
WorkerGroup () | |
Constructor. | |
void | reportTo (std::string isname) |
set name to report to IS as | |
void | reportInterval (int msec) |
set interval in msec between reports | |
Protected Types | |
typedef std::vector< Worker * > | WorkerStore |
typedef WorkerStore::iterator | Iterator |
typedef WorkerStore::const_iterator | ConstIterator |
Protected Member Functions | |
virtual void | reportThreadMain (Reporter &reporter) throw () |
thread which reports the progress of the workers to IS | |
virtual void | threadMain (Worker &worker) throw () |
The threadMain method. | |
virtual bool | popAndWork (Worker &worker) |
If the queue length != 0, removes an element from the queue and class work. | |
virtual void | waitForData () |
Called if there is no data on the queue. | |
virtual void | work (DataType data)=0 throw () |
To be overriden! Should actually do something with the data! | |
void | wait (int msec) |
Causes this thread to sleep for msec milliseconds. | |
void | addWorker (Worker &worker) |
threadMain should call this with its parameter. | |
Protected Attributes | |
Worker thread information @{ | |
This map allows each thread to access different particular information from its own Worker. | |
WorkerStore | m_workers |
Contains the queue to which objects of type T are pushed. Also useful functions to control and query the worker threads. The template class ``T'' is the data/instructions which the workers at to work on. Derive this class to implement/modify the behaviour of the worker threads. At the least, the work method needs an implementation. T must be DefaultConstructible For a simple example, see the test/MyWorkerGroup.h file
Definition at line 28 of file WorkerGroup.h.
|
destructor
Definition at line 90 of file WorkerGroup.h. |
|
Constructor.
Definition at line 93 of file WorkerGroup.h. |
|
timer watch
Definition at line 411 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_nDone, SctService::WorkerGroup< T >::m_reportAccess, and SctService::WorkerGroup< T >::m_time. Referenced by SctService::WorkerGroup< T >::popAndWork(). |
|
threadMain should call this with its parameter.
Definition at line 286 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_vectorAccess. |
|
get the number of threads which are busy.
Definition at line 370 of file WorkerGroup.h. |
|
Get the sleep time.
Definition at line 78 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::waitForData(). |
|
Start this worker group. the number of worker threads to be started.
Definition at line 210 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_thread_group, SctService::WorkerGroup< T >::Reporter, and SctService::WorkerGroup< T >::Worker. |
|
Call this to make sure that Worker threads continue to completion.
Definition at line 351 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_thread_group. Referenced by SctService::WorkerGroup< T >::stop(). |
|
get the number of jobs done
Definition at line 335 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_nDone. |
|
get the number of workers in the map
Definition at line 340 of file WorkerGroup.h. |
|
get the number of paused threads
Definition at line 361 of file WorkerGroup.h. |
|
If the queue length != 0, removes an element from the queue and class work.
Definition at line 312 of file WorkerGroup.h. References SctService::WorkerGroup< T >::addTime(), SctService::WorkerGroup< T >::m_queue, SctService::WorkerGroup< T >::m_queueAccess, SctService::WorkerGroup< T >::Worker::setBusy(), and SctService::WorkerGroup< T >::work(). |
Here is the call graph for this function:
|
Push an object onto the back of the queue.
Definition at line 292 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_queue, and SctService::WorkerGroup< T >::m_queueAccess. |
|
get the number of objects in the queue
Definition at line 330 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_queue. |
|
set interval in msec between reports
Definition at line 403 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_reportAccess, and SctService::WorkerGroup< T >::m_reportInterval. |
|
thread which reports the progress of the workers to IS
Definition at line 239 of file WorkerGroup.h. References Sct::ISUtilities::addOrUpdateOrThrow(). |
Here is the call graph for this function:
|
set name to report to IS as
Definition at line 397 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_reportAccess, and SctService::WorkerGroup< T >::m_reportTo. |
|
Set sleep time for all workers, if no items are on the queue.
Definition at line 379 of file WorkerGroup.h. References SctService::WorkerGroup< T >::m_sleeptime. |
|
Raise flag to stop all worker threads.
Definition at line 345 of file WorkerGroup.h. References SctService::WorkerGroup< T >::join(), and SctService::WorkerGroup< T >::m_run. |
Here is the call graph for this function:
|
The threadMain method. Can be overriden if sub-classes want to completly change the behaviour! Current implementation checks various flags for pausing, stopping etc, then calls popAndWork. If popAndWork returns false, then it calls waitForData Definition at line 219 of file WorkerGroup.h. |
|
Causes this thread to sleep for msec milliseconds.
Definition at line 384 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::waitForData(). |
|
Called if there is no data on the queue. Calls wait in default implementation. Definition at line 392 of file WorkerGroup.h. References SctService::WorkerGroup< T >::getSleepTime(), and SctService::WorkerGroup< T >::wait(). |
Here is the call graph for this function:
|
To be overriden! Should actually do something with the data!
Referenced by SctService::WorkerGroup< T >::popAndWork(). |
|
timer watch
Definition at line 204 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::go(). |
|
timer watch
Definition at line 203 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::go(). |
|
count of number of jobs done
Definition at line 201 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::addTime(), and SctService::WorkerGroup< T >::nDone(). |
|
does not execute work() if true
Definition at line 193 of file WorkerGroup.h. |
|
timer watch
Definition at line 186 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::popAndWork(), SctService::WorkerGroup< T >::push(), and SctService::WorkerGroup< T >::queueSize(). |
|
queueLock
Definition at line 198 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::popAndWork(), and SctService::WorkerGroup< T >::push(). |
|
vectorOfWorkersLock
Definition at line 200 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::addTime(), SctService::WorkerGroup< T >::reportInterval(), and SctService::WorkerGroup< T >::reportTo(). |
|
name to report to IS
Definition at line 196 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::reportInterval(). |
|
name to report to IS
Definition at line 195 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::reportTo(). |
|
if false, threads are to stop.
Definition at line 192 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::stop(). |
|
time to sleep if queue is empty
Definition at line 194 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::setSleepTime(). |
|
boost thread group from which threads can be created
Definition at line 190 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::go(), and SctService::WorkerGroup< T >::join(). |
|
time taken working
Definition at line 202 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::addTime(). |
|
vectorOfWorkersLock
Definition at line 199 of file WorkerGroup.h. Referenced by SctService::WorkerGroup< T >::addWorker(). |