#include <mcllib/MCThreadJob.h>
Inheritance diagram for MCThreadJob:
Public Types | |
enum | EPriority { THRJOBPRILOW, THRJOBPRINORMAL, THRJOBPRIHIGH, THRJOBPRIURGENT } |
Priority of the job with respect to other jobs in the same thread pool. More... | |
Public Member Functions | |
mcuint32 | getMaxConcurrency () const |
Get the maximum concurrency. | |
mcuint32 | getMinConcurrency () const |
Get the minimum concurrency. | |
const MCString & | getName () const |
Get the name of the job used at construction time. | |
EPriority | getPriority () const |
Get the priority of the job. | |
MCThreadJob (const MCString &name=MCString(0), mcuint32 minConcurrency=1, mcuint32 maxConcurrency=1, EPriority pri=THRJOBPRINORMAL) | |
Construct a thread job To ensure only one of the thread pool's threads calls the work method the minimum and maximum concurrency should be set to one. | |
virtual bool | work () |
Interface to job. | |
virtual | ~MCThreadJob () |
Allow virtual delete. | |
Protected Member Functions | |
void | addTask () |
Derived classes should call this after adding a task. | |
void | setDone () |
Call this when done. | |
Friends | |
class | mclpriv::ThreadJobRunnable |
class | mclpriv::ThreadPoolImpl |
Derived classes override the work() method which is called by the thread pool. The constructor allows a minimum and maximum concurrency to be specified. If the maximum concurrency is more than one, then the work method must be thread-safe because the thread job can have multiple threads working on it. To ensure only one of the thread pool's threads calls the work method the minimum and maximum concurrency should be set to one.
|
Priority of the job with respect to other jobs in the same thread pool. The thread pool itself will contain threads which have their own priority. The thread job priority is used to determine which jobs get the threads that are available.
|
|
Construct a thread job To ensure only one of the thread pool's threads calls the work method the minimum and maximum concurrency should be set to one. If minConcurrency is greater than maxConcurrency, maxConcurrency is changed to be the same as minConcurrency.
|
|
Derived classes should call this after adding a task. The work function will be called by the thread pool once for each task added. If addTask is never called, work will never be called. This means that addTask must be called to have the job do anything. |
|
Get the maximum concurrency.
|
|
Get the minimum concurrency.
|
|
Get the name of the job used at construction time.
|
|
Get the priority of the job.
|
|
Call this when done. Signals that any threads waiting for work should stop waiting once all work has been done. Do not call addTask() once setDone has been called. |
|
Interface to job. Derived classes override this to have the job do something. Return false to indicate work is done. The default implementation returns false always. If the min and max concurrency are both one then the thread pool will ensure that only one of its threads calls the work method. Note that the work method will not be called by the thread pool unless the addTask() method has been called. The thread pool will call the work method once for each time the addTask() method has been called. If the derived class wants the work method to be called only once it could call addTask() in the constructor.
|