10#ifndef INCLUDED_COMPHELPER_THREADPOOL_HXX
11#define INCLUDED_COMPHELPER_THREADPOOL_HXX
17#include <condition_variable>
30 std::shared_ptr<ThreadTaskTag>
mpTag;
40 ThreadTask(std::shared_ptr<ThreadTaskTag> pTag);
51 static std::shared_ptr<ThreadTaskTag> createThreadTaskTag();
53 static bool isTaskTagDone(
const std::shared_ptr<ThreadTaskTag>&);
59 static std::size_t getPreferredConcurrency();
65 void pushTask( std::unique_ptr<ThreadTask> pTask);
70 void waitUntilDone(
const std::shared_ptr<ThreadTaskTag>&,
bool bJoin =
true);
73 void joinThreadsIfIdle();
76 bool isIdle()
const {
return maTasks.empty() && mnBusyWorkers == 0; };
95 std::unique_ptr<ThreadTask> popWorkLocked( std::unique_lock< std::mutex > & rGuard,
bool bWait );
96 void shutdownLocked(std::unique_lock<std::mutex>&);
106 std::vector< std::unique_ptr<ThreadTask> >
maTasks;
107 std::vector< rtl::Reference< ThreadWorker > >
maWorkers;
A very basic thread-safe thread pool implementation.
std::size_t const mnMaxWorkers
std::condition_variable maTasksChanged
std::size_t mnBusyWorkers
std::vector< rtl::Reference< ThreadWorker > > maWorkers
ThreadPool & operator=(const ThreadPool &)=delete
std::vector< std::unique_ptr< ThreadTask > > maTasks
ThreadPool(const ThreadPool &)=delete
bool isIdle() const
return true if there are no queued or worked-on tasks
sal_Int32 getWorkerCount() const
return the number of live worker threads
std::mutex maMutex
signalled when all in-progress tasks are complete
std::shared_ptr< ThreadTaskTag > mpTag
virtual void doWork()=0
override to get your task performed by the pool
virtual ~ThreadTask()
once pushed ThreadTasks are destroyed by the pool
#define COMPHELPER_DLLPUBLIC