GDAL
Public Member Functions | List of all members
CPLWorkerThreadPool Class Reference

Pool of worker threads. More...

#include <cpl_worker_thread_pool.h>

Public Member Functions

 CPLWorkerThreadPool ()
 Instantiate a new pool of worker threads. More...
 
 ~CPLWorkerThreadPool ()
 Destroys a pool of worker threads. More...
 
bool Setup (int nThreads, CPLThreadFunc pfnInitFunc, void **pasInitData)
 Setup the pool. More...
 
bool Setup (int nThreads, CPLThreadFunc pfnInitFunc, void **pasInitData, bool bWaitallStarted)
 Setup the pool. More...
 
bool SubmitJob (CPLThreadFunc pfnFunc, void *pData)
 Queue a new job. More...
 
bool SubmitJobs (CPLThreadFunc pfnFunc, const std::vector< void *> &apData)
 Queue several jobs. More...
 
void WaitCompletion (int nMaxRemainingJobs=0)
 Wait for completion of part or whole jobs. More...
 
void WaitEvent ()
 Wait for completion of at least one job, if there are any remaining.
 
int GetThreadCount () const
 Return the number of threads setup.
 

Detailed Description

Pool of worker threads.

Constructor & Destructor Documentation

◆ CPLWorkerThreadPool()

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()

CPLWorkerThreadPool::~CPLWorkerThreadPool ( )

Destroys a pool of worker threads.

Any still pending job will be completed before the destructor returns.

Member Function Documentation

◆ Setup() [1/2]

bool CPLWorkerThreadPool::Setup ( int  nThreads,
CPLThreadFunc  pfnInitFunc,
void **  pasInitData 
)

Setup the pool.

Parameters
nThreadsNumber of threads to launch
pfnInitFuncInitialization function to run in each thread. May be NULL
pasInitDataArray 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
nThreadsNumber of threads to launch
pfnInitFuncInitialization function to run in each thread. May be NULL
pasInitDataArray of initialization data. Its length must be nThreads, or it should be NULL.
bWaitallStartedWhether to wait for all threads to be fully started.
Returns
true if initialization was successful.

◆ SubmitJob()

bool CPLWorkerThreadPool::SubmitJob ( CPLThreadFunc  pfnFunc,
void *  pData 
)

Queue a new job.

Parameters
pfnFuncFunction to run for the job.
pDataUser data to pass to the job function.
Returns
true in case of success.

◆ SubmitJobs()

bool CPLWorkerThreadPool::SubmitJobs ( CPLThreadFunc  pfnFunc,
const std::vector< void *> &  apData 
)

Queue several jobs.

Parameters
pfnFuncFunction to run for the job.
apDataUser 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
nMaxRemainingJobsMaximum number of pendings jobs that are allowed in the queue after this method has completed. Might be 0 to wait for all jobs.

The documentation for this class was generated from the following files:

Generated for GDAL by doxygen 1.8.13.