98 bool isRunning() const noexcept {
return isActive; }
114 void signalJobShouldExit();
137 std::atomic<bool> shouldStop {
false }, isActive {
false }, shouldBeDeleted {
false };
138 ListenerList<Thread::Listener, Array<Thread::Listener*, CriticalSection>> listeners;
140 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ThreadPoolJob)
159 return withMember (*
this, &ThreadPoolOptions::threadName, newThreadName);
167 return withMember (*
this, &ThreadPoolOptions::numberOfThreads, newNumberOfThreads);
173 return withMember (*
this, &ThreadPoolOptions::threadStackSizeBytes, newThreadStackSizeBytes);
179 return withMember (*
this, &ThreadPoolOptions::desiredThreadPriority, newDesiredThreadPriority);
182 String threadName {
"Pool" };
184 size_t threadStackSizeBytes { Thread::osDefaultStackSize };
233 size_t threadStackSizeBytes = Thread::osDefaultStackSize,
278 void addJob (ThreadPoolJob* job,
279 bool deleteJobWhenFinished);
289 void addJob (std::function<
void()> job);
309 bool interruptIfRunning,
310 int timeOutMilliseconds);
324 int timeOutMilliseconds,
338 ThreadPoolJob*
getJob (
int index) const noexcept;
344 bool contains (const ThreadPoolJob* job) const noexcept;
347 bool isJobRunning (const ThreadPoolJob* job) const noexcept;
358 int timeOutMilliseconds) const;
372 Array<ThreadPoolJob*> jobs;
374 struct ThreadPoolThread;
375 friend class ThreadPoolJob;
381 bool runNextJob (ThreadPoolThread&);
382 ThreadPoolJob* pickNextJobToRun();
383 void addToDeleteList (
OwnedArray<ThreadPoolJob>&, ThreadPoolJob*) const;
390 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (
ThreadPool)
static int getNumCpus() noexcept
void setJobName(const String &newName)
String getJobName() const
bool isRunning() const noexcept
bool shouldExit() const noexcept
virtual JobStatus runJob()=0
ThreadPoolJob(const String &name)
virtual bool isJobSuitable(ThreadPoolJob *job)=0
void moveJobToFront(const ThreadPoolJob *jobToMove) noexcept
void addJob(ThreadPoolJob *job, bool deleteJobWhenFinished)
int getNumThreads() const noexcept
ThreadPoolJob * getJob(int index) const noexcept
int getNumJobs() const noexcept
bool removeAllJobs(bool interruptRunningJobs, int timeOutMilliseconds, JobSelector *selectedJobsToRemove=nullptr)
StringArray getNamesOfAllJobs(bool onlyReturnActiveJobs) const
ThreadPool(const Options &options)
bool isJobRunning(const ThreadPoolJob *job) const noexcept
bool removeJob(ThreadPoolJob *job, bool interruptIfRunning, int timeOutMilliseconds)
bool contains(const ThreadPoolJob *job) const noexcept
bool waitForJobToFinish(const ThreadPoolJob *job, int timeOutMilliseconds) const
ThreadPoolOptions withThreadName(String newThreadName) const
ThreadPoolOptions withNumberOfThreads(int newNumberOfThreads) const
ThreadPoolOptions withDesiredThreadPriority(Thread::Priority newDesiredThreadPriority) const
ThreadPoolOptions withThreadStackSizeBytes(size_t newThreadStackSizeBytes) const