JUCE
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Public Types | Public Member Functions
ThreadPoolJob Class Reference

A task that is executed by a ThreadPool object. More...

List of all members.

Public Types

enum  JobStatus { jobHasFinished = 0, jobNeedsRunningAgain }
 These are the values that can be returned by the runJob() method. More...

Public Member Functions

 ThreadPoolJob (const String &name)
 Creates a thread pool job object.
virtual ~ThreadPoolJob ()
 Destructor.
String getJobName () const
 Returns the name of this job.
void setJobName (const String &newName)
 Changes the job's name.
virtual JobStatus runJob ()=0
 Peforms the actual work that this job needs to do.
bool isRunning () const noexcept
 Returns true if this job is currently running its runJob() method.
bool shouldExit () const noexcept
 Returns true if something is trying to interrupt this job and make it stop.
void signalJobShouldExit ()
 Calling this will cause the shouldExit() method to return true, and the job should (if it's been implemented correctly) stop as soon as possible.

Detailed Description

A task that is executed by a ThreadPool object.

A ThreadPool keeps a list of ThreadPoolJob objects which are executed by its threads.

The runJob() method needs to be implemented to do the task, and if the code that does the work takes a significant time to run, it must keep checking the shouldExit() method to see if something is trying to interrupt the job. If shouldExit() returns true, the runJob() method must return immediately.

See also:
ThreadPool, Thread

Member Enumeration Documentation

These are the values that can be returned by the runJob() method.

Enumerator:
jobHasFinished 

indicates that the job has finished and can be removed from the pool.

jobNeedsRunningAgain 

indicates that the job would like to be called again when a thread is free.


Constructor & Destructor Documentation

ThreadPoolJob::ThreadPoolJob ( const String name) [explicit]

Creates a thread pool job object.

After creating your job, add it to a thread pool with ThreadPool::addJob().

virtual ThreadPoolJob::~ThreadPoolJob ( ) [virtual]

Destructor.


Member Function Documentation

Returns the name of this job.

See also:
setJobName
void ThreadPoolJob::setJobName ( const String newName)

Changes the job's name.

See also:
getJobName
virtual JobStatus ThreadPoolJob::runJob ( ) [pure virtual]

Peforms the actual work that this job needs to do.

Your subclass must implement this method, in which is does its work.

If the code in this method takes a significant time to run, it must repeatedly check the shouldExit() method to see if something is trying to interrupt the job. If shouldExit() ever returns true, the runJob() method must return immediately.

If this method returns jobHasFinished, then the job will be removed from the pool immediately. If it returns jobNeedsRunningAgain, then the job will be left in the pool and will get a chance to run again as soon as a thread is free.

See also:
shouldExit()
bool ThreadPoolJob::isRunning ( ) const

Returns true if this job is currently running its runJob() method.

bool ThreadPoolJob::shouldExit ( ) const

Returns true if something is trying to interrupt this job and make it stop.

Your runJob() method must call this whenever it gets a chance, and if it ever returns true, the runJob() method must return immediately.

See also:
signalJobShouldExit()

Calling this will cause the shouldExit() method to return true, and the job should (if it's been implemented correctly) stop as soon as possible.

See also:
shouldExit()

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