mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-15 00:24:19 +00:00
Added method ThreadPool::moveJobToFront()
This commit is contained in:
parent
dc8033633c
commit
4e69133e54
2 changed files with 29 additions and 11 deletions
|
|
@ -161,34 +161,47 @@ void ThreadPool::addJob (std::function<void()> jobToRun)
|
|||
addJob (new LambdaJobWrapper (jobToRun), true);
|
||||
}
|
||||
|
||||
int ThreadPool::getNumJobs() const
|
||||
int ThreadPool::getNumJobs() const noexcept
|
||||
{
|
||||
return jobs.size();
|
||||
}
|
||||
|
||||
int ThreadPool::getNumThreads() const
|
||||
int ThreadPool::getNumThreads() const noexcept
|
||||
{
|
||||
return threads.size();
|
||||
}
|
||||
|
||||
ThreadPoolJob* ThreadPool::getJob (const int index) const
|
||||
ThreadPoolJob* ThreadPool::getJob (int index) const noexcept
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
return jobs [index];
|
||||
}
|
||||
|
||||
bool ThreadPool::contains (const ThreadPoolJob* const job) const
|
||||
bool ThreadPool::contains (const ThreadPoolJob* const job) const noexcept
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
return jobs.contains (const_cast<ThreadPoolJob*> (job));
|
||||
}
|
||||
|
||||
bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
|
||||
bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const noexcept
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
return jobs.contains (const_cast<ThreadPoolJob*> (job)) && job->isActive;
|
||||
}
|
||||
|
||||
void ThreadPool::moveJobToFront (const ThreadPoolJob* job) noexcept
|
||||
{
|
||||
const ScopedLock sl (lock);
|
||||
|
||||
if (! ! job->isActive)
|
||||
{
|
||||
auto index = jobs.indexOf (const_cast<ThreadPoolJob*> (job));
|
||||
|
||||
if (index > 0)
|
||||
jobs.move (index, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job, const int timeOutMs) const
|
||||
{
|
||||
if (job != nullptr)
|
||||
|
|
@ -272,7 +285,7 @@ bool ThreadPool::removeAllJobs (const bool interruptRunningJobs, const int timeO
|
|||
}
|
||||
}
|
||||
|
||||
const uint32 start = Time::getMillisecondCounter();
|
||||
auto start = Time::getMillisecondCounter();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -254,26 +254,26 @@ public:
|
|||
JobSelector* selectedJobsToRemove = nullptr);
|
||||
|
||||
/** Returns the number of jobs currently running or queued. */
|
||||
int getNumJobs() const;
|
||||
int getNumJobs() const noexcept;
|
||||
|
||||
/** Returns the number of threads assigned to this thread pool. */
|
||||
int getNumThreads() const;
|
||||
int getNumThreads() const noexcept;
|
||||
|
||||
/** Returns one of the jobs in the queue.
|
||||
|
||||
Note that this can be a very volatile list as jobs might be continuously getting shifted
|
||||
around in the list, and this method may return nullptr if the index is currently out-of-range.
|
||||
*/
|
||||
ThreadPoolJob* getJob (int index) const;
|
||||
ThreadPoolJob* getJob (int index) const noexcept;
|
||||
|
||||
/** Returns true if the given job is currently queued or running.
|
||||
|
||||
@see isJobRunning()
|
||||
*/
|
||||
bool contains (const ThreadPoolJob* job) const;
|
||||
bool contains (const ThreadPoolJob* job) const noexcept;
|
||||
|
||||
/** Returns true if the given job is currently being run by a thread. */
|
||||
bool isJobRunning (const ThreadPoolJob* job) const;
|
||||
bool isJobRunning (const ThreadPoolJob* job) const noexcept;
|
||||
|
||||
/** Waits until a job has finished running and has been removed from the pool.
|
||||
|
||||
|
|
@ -286,6 +286,11 @@ public:
|
|||
bool waitForJobToFinish (const ThreadPoolJob* job,
|
||||
int timeOutMilliseconds) const;
|
||||
|
||||
/** If the given job is in the queue, this will move it to the front so that it
|
||||
is the next one to be executed.
|
||||
*/
|
||||
void moveJobToFront (const ThreadPoolJob* jobToMove) noexcept;
|
||||
|
||||
/** Returns a list of the names of all the jobs currently running or queued.
|
||||
If onlyReturnActiveJobs is true, only the ones currently running are returned.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue