Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCThreadJob Class Reference

Base class for thread pool jobs (see MCThreadPool). More...

#include <mcllib/MCThreadJob.h>

Inheritance diagram for MCThreadJob:

MCRefCount MCBase List of all members.

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 MCStringgetName () 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

Detailed Description

Base class for thread pool jobs (see MCThreadPool).

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.

See also:
MCThreadPool


Member Enumeration Documentation

enum EPriority
 

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.

Todo:
Thread job priorities are not used by the thread pool
Enumeration values:
THRJOBPRILOW  Low priority job.
THRJOBPRINORMAL  Normal priority job.
THRJOBPRIHIGH  High priority job.
THRJOBPRIURGENT  Urgent priority job.


Constructor & Destructor Documentation

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.

If minConcurrency is greater than maxConcurrency, maxConcurrency is changed to be the same as minConcurrency.

Parameters:
name the name of the job for diagnostic purposes.
minConcurrency the minimum number of threads which must be executing the work method of the job if there is work to do.
maxConcurrency the maximum number of threads which may be executing the work method of the job
pri the job priority with respect to other jobs in the same thread pool. Note that the priority is currently ignored.
Todo:
implement thread job priority


Member Function Documentation

void addTask  )  [protected]
 

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.

mcuint32 getMaxConcurrency  )  const
 

Get the maximum concurrency.

Returns:
the maximum concurrency of the job

mcuint32 getMinConcurrency  )  const
 

Get the minimum concurrency.

Returns:
the minimum concurrency of the job

const MCString& getName  )  const
 

Get the name of the job used at construction time.

Returns:
the name of the job

EPriority getPriority  )  const
 

Get the priority of the job.

Returns:
the job priority

void setDone  )  [protected]
 

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.

virtual bool work  )  [virtual]
 

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.

Returns:
true if work is not done, false if work is done


Generated on Wed Jan 12 19:05:50 2005 for MCLLIB by  doxygen 1.3.9.1