30#ifndef CPL_WORKER_THREAD_POOL_H_INCLUDED_
31#define CPL_WORKER_THREAD_POOL_H_INCLUDED_
33#include "cpl_multiproc.h"
36#include <condition_variable>
49struct CPLWorkerThreadJob;
55 CPLWorkerThread() =
default;
57 CPLThreadFunc pfnInitFunc =
nullptr;
58 void *pInitData =
nullptr;
60 CPLJoinableThread *hThread =
nullptr;
61 bool bMarkedAsWaiting =
false;
64 std::condition_variable m_cv{};
72} CPLWorkerThreadState;
82 std::vector<std::unique_ptr<CPLWorkerThread>> aWT{};
84 std::condition_variable m_cv{};
85 volatile CPLWorkerThreadState eState = CPLWTS_OK;
89 CPLList *psWaitingWorkerThreadsList =
nullptr;
90 int nWaitingWorkerThreads = 0;
92 int m_nMaxThreads = 0;
94 static void WorkerThreadFunction(
void *user_data);
96 void DeclareJobFinished();
97 CPLWorkerThreadJob *GetNextJob(CPLWorkerThread *psWorkerThread);
103 bool Setup(
int nThreads, CPLThreadFunc pfnInitFunc,
void **pasInitData);
104 bool Setup(
int nThreads, CPLThreadFunc pfnInitFunc,
void **pasInitData,
105 bool bWaitallStarted);
107 std::unique_ptr<CPLJobQueue> CreateJobQueue();
109 bool SubmitJob(CPLThreadFunc pfnFunc,
void *pData);
110 bool SubmitJobs(CPLThreadFunc pfnFunc,
const std::vector<void *> &apData);
111 void WaitCompletion(
int nMaxRemainingJobs = 0);
117 return m_nMaxThreads;
126 std::mutex m_mutex{};
127 std::condition_variable m_cv{};
128 int m_nPendingJobs = 0;
130 static void JobQueueFunction(
void *);
131 void DeclareJobFinished();
148 bool SubmitJob(CPLThreadFunc pfnFunc,
void *pData);
149 void WaitCompletion(
int nMaxRemainingJobs = 0);
Job queue.
Definition: cpl_worker_thread_pool.h:123
CPLWorkerThreadPool * GetPool()
Return the owning worker thread pool.
Definition: cpl_worker_thread_pool.h:143
Pool of worker threads.
Definition: cpl_worker_thread_pool.h:79
int GetThreadCount() const
Return the number of threads setup.
Definition: cpl_worker_thread_pool.h:115
Simplest list implementation.
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:1042
List element structure.
Definition: cpl_list.h:52