Pool of worker threads.
More...
#include <cpl_worker_thread_pool.h>
|
| | CPLWorkerThreadPool () |
| | Instantiate a new pool of worker threads.
|
| | CPLWorkerThreadPool (int nThreads) |
| | Instantiate a new pool of worker threads.
|
| | ~CPLWorkerThreadPool () |
| | Destroys a pool of worker threads.
|
| bool | Setup (int nThreads, CPLThreadFunc pfnInitFunc, void **pasInitData) |
| | Setup the pool.
|
| bool | Setup (int nThreads, CPLThreadFunc pfnInitFunc, void **pasInitData, bool bWaitallStarted) |
| | Setup the pool.
|
| CPLJobQueuePtr | CreateJobQueue () |
| | Create a new job queue based on this worker thread pool.
|
| bool | SubmitJob (std::function< void()> task) |
| | Queue a new job.
|
| bool | SubmitJob (CPLThreadFunc pfnFunc, void *pData) |
| | Queue a new job.
|
| bool | SubmitJobs (CPLThreadFunc pfnFunc, const std::vector< void * > &apData) |
| | Queue several jobs.
|
| void | WaitCompletion (int nMaxRemainingJobs=0) |
| | Wait for completion of part or whole jobs.
|
|
void | WaitEvent () |
| | Wait for completion of at least one job, if there are any remaining, or for WakeUpWaitEvent() to have been called.
|
| void | WakeUpWaitEvent () |
| | Wake-up WaitEvent().
|
|
int | GetThreadCount () const |
| | Return the number of threads setup.
|
◆ CPLWorkerThreadPool() [1/2]
| CPLWorkerThreadPool::CPLWorkerThreadPool |
( |
| ) |
|
Instantiate a new pool of worker threads.
The pool is in an uninitialized state after this call. The Setup() method must be called.
◆ CPLWorkerThreadPool() [2/2]
| CPLWorkerThreadPool::CPLWorkerThreadPool |
( |
int | nThreads | ) |
|
|
explicit |
Instantiate a new pool of worker threads.
- Parameters
-
| nThreads | Number of threads in the pool. |
◆ ~CPLWorkerThreadPool()
| CPLWorkerThreadPool::~CPLWorkerThreadPool |
( |
| ) |
|
Destroys a pool of worker threads.
Any still pending job will be completed before the destructor returns.
◆ CreateJobQueue()
| std::unique_ptr< CPLJobQueue > CPLWorkerThreadPool::CreateJobQueue |
( |
| ) |
|
Create a new job queue based on this worker thread pool.
The worker thread pool must remain alive while the returned object is itself alive.
- Since
- GDAL 3.2
◆ Setup() [1/2]
| bool CPLWorkerThreadPool::Setup |
( |
int | nThreads, |
|
|
CPLThreadFunc | pfnInitFunc, |
|
|
void ** | pasInitData ) |
Setup the pool.
- Parameters
-
| nThreads | Number of threads to launch |
| pfnInitFunc | Initialization function to run in each thread. May be NULL |
| pasInitData | Array of initialization data. Its length must be nThreads, or it should be NULL. |
- Returns
- true if initialization was successful.
◆ Setup() [2/2]
| bool CPLWorkerThreadPool::Setup |
( |
int | nThreads, |
|
|
CPLThreadFunc | pfnInitFunc, |
|
|
void ** | pasInitData, |
|
|
bool | bWaitallStarted ) |
Setup the pool.
- Parameters
-
| nThreads | Number of threads to launch |
| pfnInitFunc | Initialization function to run in each thread. May be NULL |
| pasInitData | Array of initialization data. Its length must be nThreads, or it should be NULL. |
| bWaitallStarted | Whether to wait for all threads to be fully started. |
- Returns
- true if initialization was successful.
◆ SubmitJob() [1/2]
| bool CPLWorkerThreadPool::SubmitJob |
( |
CPLThreadFunc | pfnFunc, |
|
|
void * | pData ) |
Queue a new job.
- Parameters
-
| pfnFunc | Function to run for the job. |
| pData | User data to pass to the job function. |
- Returns
- true in case of success.
◆ SubmitJob() [2/2]
| bool CPLWorkerThreadPool::SubmitJob |
( |
std::function< void()> | task | ) |
|
Queue a new job.
- Parameters
-
| task | Void function to execute. |
- Returns
- true in case of success.
if (!wt->hThread) { VSIFree(psJob); VSIFree(psItem); return false; }
◆ SubmitJobs()
| bool CPLWorkerThreadPool::SubmitJobs |
( |
CPLThreadFunc | pfnFunc, |
|
|
const std::vector< void * > & | apData ) |
Queue several jobs.
- Parameters
-
| pfnFunc | Function to run for the job. |
| apData | User data instances to pass to the job function. |
- Returns
- true in case of success.
◆ WaitCompletion()
| void CPLWorkerThreadPool::WaitCompletion |
( |
int | nMaxRemainingJobs = 0 | ) |
|
Wait for completion of part or whole jobs.
- Parameters
-
| nMaxRemainingJobs | Maximum number of pendings jobs that are allowed in the queue after this method has completed. Might be 0 to wait for all jobs. |
◆ WakeUpWaitEvent()
| void CPLWorkerThreadPool::WakeUpWaitEvent |
( |
| ) |
|
Wake-up WaitEvent().
This method is thread-safe.
- Since
- GDAL 3.12
The documentation for this class was generated from the following files: