12#ifndef ROOT_TThreadPool
13#define ROOT_TThreadPool
34#define sleep(s) _sleep(s)
72template <
class aTask,
class aParam>
75 bool run(aParam ¶m) {
76 aTask *pThis =
reinterpret_cast<aTask *
>(
this);
77 return pThis->runTask(param);
89template <
class aTask,
class aParam>
118template <
class aTask,
class aParam>
136 for (
size_t i = 0; i < threadsCount; ++i) {
153 threads_array_t::const_iterator iter =
fThreads.begin();
154 threads_array_t::const_iterator iter_end =
fThreads.end();
155 for (; iter != iter_end; ++iter)
175 DbgLog(
"Main thread. Try to push a task");
182 DbgLog(
"Main thread. the task is pushed");
188 void Stop(
bool processRemainingJobs =
false) {
193 if (processRemainingJobs) {
197 DbgLog(
"Main thread is waiting");
199 DbgLog(
"Main thread is DONE waiting");
207 DbgLog(
"Main threads requests to STOP");
241 std::stringstream ss;
243 <<
">>>> Check for tasks."
244 <<
" Number of Tasks: " << pThis->
fTasks.size()
263 pThis->
DbgLog(
"waiting for a task");
273 pThis->
DbgLog(
"done waiting for tasks");
279 if (!pThis->
fTasks.empty()) {
281 task = pThis->
fTasks.front();
284 pThis->
DbgLog(
"get the task");
289 pThis->
DbgLog(
"done Check <<<<");
294 pThis->
DbgLog(
"Run the task");
306 pThis->
DbgLog(
"Done Running the task");
313 pThis->
DbgLog(
"**** DONE ***");
319 threads_array_t::const_iterator iter = pThis->
fThreads.begin();
320 threads_array_t::const_iterator iter_end = pThis->
fThreads.end();
321 for (; iter != iter_end; ++iter)
R__EXTERN C unsigned int sleep(unsigned int seconds)
Int_t Wait()
Wait to be signaled.
const TNonCopyable & operator=(const TNonCopyable &)
TNonCopyable(const TNonCopyable &)
TThreadPoolTask(task_t &task, aParam ¶m)
TThreadPoolTaskImp< aTask, aParam > task_t
TThreadPool(size_t threadsCount, bool needDbg=false)
TThreadPoolTask< aTask, aParam > task_t
TCondition * fThreadAvailable
size_t TasksCount() const
TMutex fMutexAllTasksDone
void Stop(bool processRemainingJobs=false)
TThread * fThreadJoinHelper
TCondition * fAllTasksDone
static void * Executor(void *arg)
static bool IsThreadActive(TThread *pThread)
static void * JoinHelper(void *arg)
void DbgLog(const std::string &msg)
static void * Monitor(void *arg)
TCondition * fThreadNeeded
size_t IdleThreads() const
void PushTask(typename TThreadPoolTask< aTask, aParam >::task_t &task, aParam param)
size_t SuccessfulTasks() const
std::vector< TThread * > threads_array_t
std::queue< task_t * > taskqueue_t
Long_t Join(void **ret=nullptr)
Join this thread.
static Long_t SelfId()
Static method returning the id for the current thread.
Int_t Run(void *arg=nullptr)
Start the thread.