Om
1.0.0
A universal framework for multimedia simulation
|
A class that executes jobs on a set of worker threads. More...
#include <omThreadPool.h>
Public Member Functions | |
ThreadPool () | |
Create a thread pool which has no threads and no jobs queued. More... | |
ThreadPool (Size newNumberOfThreads) | |
Create a new thread pool which has the specified number of execution threads. More... | |
~ThreadPool () | |
Finish the current job being processed by each worker thread then destroy the thread pool. More... | |
Size | getThreadCount () const |
Return the number of threads that are currently executing as part of this thread pool. More... | |
void | setThreadCount (Size numThreads) |
Set the desired number of threads that should be in this thread pool. More... | |
void | addThread () |
Add a new worker thread to this thread pool. More... | |
void | removeThread () |
Wait for a thread to finish processing and remove it from the queue. More... | |
Index | getCurrentThreadIndex () const |
Return the index of the thread in this thread pool corresponding to the calling thread, or -1 if no match found. More... | |
Size | getJobCount () const |
Return the total number of jobs that are queued to be executed by this thread pool. More... | |
template<typename Signature > | |
void | addJob (const lang::FunctionCall< Signature > &job, Index jobID=0, Float priority=Float(0), Index threadIndex=Index(-1)) |
Add the specified job function call to this thread pool, executing with the given priority. More... | |
void | finishJob (Index jobID) |
Wait for all of the jobs queued in this thread pool for the specified job ID to finish. More... | |
void | finishJobs () |
Wait for all of the jobs queued in this thread pool to finish before returning. More... | |
void | clearJobs () |
Remove all currently queued jobs from this thread pool. More... | |
ThreadPriority | getPriority () const |
Return the thread priority that is used for all of the threads in this pool. More... | |
Bool | setPriority (const ThreadPriority &newPriority) |
Set the thread priority that is used for all of the threads in this pool. More... | |
A class that executes jobs on a set of worker threads.
om::threads::ThreadPool::ThreadPool | ( | ) |
Create a thread pool which has no threads and no jobs queued.
om::threads::ThreadPool::ThreadPool | ( | Size | newNumberOfThreads | ) |
Create a new thread pool which has the specified number of execution threads.
om::threads::ThreadPool::~ThreadPool | ( | ) |
Finish the current job being processed by each worker thread then destroy the thread pool.
Size om::threads::ThreadPool::getThreadCount | ( | ) | const |
Return the number of threads that are currently executing as part of this thread pool.
void om::threads::ThreadPool::setThreadCount | ( | Size | numThreads | ) |
Set the desired number of threads that should be in this thread pool.
void om::threads::ThreadPool::addThread | ( | ) |
Add a new worker thread to this thread pool.
void om::threads::ThreadPool::removeThread | ( | ) |
Wait for a thread to finish processing and remove it from the queue.
Index om::threads::ThreadPool::getCurrentThreadIndex | ( | ) | const |
Return the index of the thread in this thread pool corresponding to the calling thread, or -1 if no match found.
Size om::threads::ThreadPool::getJobCount | ( | ) | const |
Return the total number of jobs that are queued to be executed by this thread pool.
|
inline |
Add the specified job function call to this thread pool, executing with the given priority.
The method allows the user to specify an integer ID for the job, that is used to differentiate between different job sets that have different deadlines on separate threads. The user can then wait for all jobs or just jobs with that ID to finish.
void om::threads::ThreadPool::finishJob | ( | Index | jobID | ) |
Wait for all of the jobs queued in this thread pool for the specified job ID to finish.
void om::threads::ThreadPool::finishJobs | ( | ) |
Wait for all of the jobs queued in this thread pool to finish before returning.
void om::threads::ThreadPool::clearJobs | ( | ) |
Remove all currently queued jobs from this thread pool.
|
inline |
Return the thread priority that is used for all of the threads in this pool.
Bool om::threads::ThreadPool::setPriority | ( | const ThreadPriority & | newPriority | ) |
Set the thread priority that is used for all of the threads in this pool.
The method returns whether or not the priority was successfully changed.