|
LMMS
|
#include <juce_ThreadPool.h>
Public Types | |
| enum | JobStatus { jobHasFinished = 0 , jobNeedsRunningAgain } |
Public Member Functions | |
| ThreadPoolJob (const String &name) | |
| virtual | ~ThreadPoolJob () |
| String | getJobName () const |
| void | setJobName (const String &newName) |
| virtual JobStatus | runJob ()=0 |
| bool | isRunning () const noexcept |
| bool | shouldExit () const noexcept |
| void | signalJobShouldExit () |
| void | addListener (Thread::Listener *) |
| void | removeListener (Thread::Listener *) |
Static Public Member Functions | |
| static ThreadPoolJob * | getCurrentThreadPoolJob () |
Private Attributes | |
| String | jobName |
| ThreadPool * | pool = nullptr |
| std::atomic< bool > | shouldStop { false } |
| std::atomic< bool > | isActive { false } |
| std::atomic< bool > | shouldBeDeleted { false } |
| ListenerList< Thread::Listener, Array< Thread::Listener *, CriticalSection > > | listeners |
Friends | |
| class | ThreadPool |
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.
@tags{Core}
| enum juce::ThreadPoolJob::JobStatus |
Creates a thread pool job object. After creating your job, add it to a thread pool with ThreadPool::addJob().
|
virtual |
Destructor.
| void juce::ThreadPoolJob::addListener | ( | Thread::Listener * | listener | ) |
Add a listener to this thread job which will receive a callback when signalJobShouldExit was called on this thread job.
|
static |
If the calling thread is being invoked inside a runJob() method, this will return the ThreadPoolJob that it belongs to.
| String juce::ThreadPoolJob::getJobName | ( | ) | const |
Returns the name of this job.
|
inlinenoexcept |
Returns true if this job is currently running its runJob() method.
| void juce::ThreadPoolJob::removeListener | ( | Thread::Listener * | listener | ) |
Removes a listener added with addListener.
|
pure virtual |
Performs 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.
Implemented in juce::DragAndDropHelpers::DragAndDropJob, and juce::PluginListComponent::Scanner::ScanJob.
Changes the job's name.
|
inlinenoexcept |
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.
| void juce::ThreadPoolJob::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.
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |