10 #ifndef INCLUDED_COMPHELPER_THREADPOOL_HXX
11 #define INCLUDED_COMPHELPER_THREADPOOL_HXX
14 #include <rtl/ref.hxx>
17 #include <condition_variable>
29 std::shared_ptr<ThreadTaskTag>
mpTag;
35 virtual void doWork() = 0;
39 ThreadTask(
const std::shared_ptr<ThreadTaskTag>& pTag);
50 static std::shared_ptr<ThreadTaskTag> createThreadTaskTag();
52 static bool isTaskTagDone(
const std::shared_ptr<ThreadTaskTag>&);
58 static sal_Int32 getPreferredConcurrency();
64 void pushTask( std::unique_ptr<ThreadTask> pTask);
69 void waitUntilDone(
const std::shared_ptr<ThreadTaskTag>&,
bool bJoin =
true);
72 void joinThreadsIfIdle();
75 bool isIdle()
const {
return maTasks.empty() && mnBusyWorkers == 0; };
94 std::unique_ptr<ThreadTask> popWorkLocked( std::unique_lock< std::mutex > & rGuard,
bool bWait );
95 void shutdownLocked(std::unique_lock<std::mutex>&);
105 std::vector< std::unique_ptr<ThreadTask> >
maTasks;
106 std::vector< rtl::Reference< ThreadWorker > >
maWorkers;
111 #endif // INCLUDED_COMPHELPER_THREADPOOL_HXX
std::vector< std::unique_ptr< ThreadTask > > maTasks
A very basic thread-safe thread pool implementation.
sal_Int32 getWorkerCount() const
return the number of live worker threads
std::mutex maMutex
signalled when all in-progress tasks are complete
bool isIdle() const
return true if there are no queued or worked-on tasks
std::condition_variable maTasksChanged
std::vector< rtl::Reference< ThreadWorker > > maWorkers
std::shared_ptr< ThreadTaskTag > mpTag
std::size_t mnBusyWorkers
#define COMPHELPER_DLLPUBLIC
std::size_t const mnMaxWorkers
virtual ~ThreadTask()
once pushed ThreadTasks are destroyed by the pool