12#ifndef ROOT_TThreadPool
13#define ROOT_TThreadPool
33#define sleep(s) _sleep(s)
69template <
class aTask,
class aParam>
72 bool run(aParam ¶m) {
73 aTask *pThis =
reinterpret_cast<aTask *
>(
this);
74 return pThis->runTask(param);
86template <
class aTask,
class aParam>
115template <
class aTask,
class aParam>
133 for (
size_t i = 0; i < threadsCount; ++i) {
150 threads_array_t::const_iterator iter =
fThreads.begin();
151 threads_array_t::const_iterator iter_end =
fThreads.end();
152 for (; iter != iter_end; ++iter)
172 DbgLog(
"Main thread. Try to push a task");
179 DbgLog(
"Main thread. the task is pushed");
185 void Stop(
bool processRemainingJobs =
false) {
190 if (processRemainingJobs) {
194 DbgLog(
"Main thread is waiting");
196 DbgLog(
"Main thread is DONE waiting");
204 DbgLog(
"Main threads requests to STOP");
238 std::stringstream ss;
240 <<
">>>> Check for tasks."
241 <<
" Number of Tasks: " << pThis->
fTasks.size()
260 pThis->
DbgLog(
"waiting for a task");
270 pThis->
DbgLog(
"done waiting for tasks");
276 if (!pThis->
fTasks.empty()) {
278 task = pThis->
fTasks.front();
281 pThis->
DbgLog(
"get the task");
286 pThis->
DbgLog(
"done Check <<<<");
291 pThis->
DbgLog(
"Run the task");
303 pThis->
DbgLog(
"Done Running the task");
310 pThis->
DbgLog(
"**** DONE ***");
316 threads_array_t::const_iterator iter = pThis->
fThreads.begin();
317 threads_array_t::const_iterator iter_end = pThis->
fThreads.end();
318 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
static Long_t SelfId()
Static method returning the id for the current thread.
Long_t Join(void **ret=0)
Join this thread.
Int_t Run(void *arg=0)
Start the thread.