12 #ifndef ROOT_TThreadPool
13 #define ROOT_TThreadPool
66 template <
class aTask,
class aParam>
69 bool run(aParam ¶m) {
70 aTask *pThis =
reinterpret_cast<aTask *
>(
this);
71 return pThis->runTask(param);
83 template <
class aTask,
class aParam>
112 template <
class aTask,
class aParam>
130 for (
size_t i = 0; i < threadsCount; ++i) {
147 threads_array_t::const_iterator iter =
fThreads.begin();
148 threads_array_t::const_iterator iter_end =
fThreads.end();
149 for (; iter != iter_end; ++iter)
169 DbgLog(
"Main thread. Try to push a task");
176 DbgLog(
"Main thread. the task is pushed");
182 void Stop(
bool processRemainingJobs =
false) {
187 if (processRemainingJobs) {
191 DbgLog(
"Main thread is waiting");
193 DbgLog(
"Main thread is DONE waiting");
201 DbgLog(
"Main threads requests to STOP");
235 std::stringstream ss;
237 <<
">>>> Check for tasks."
238 <<
" Number of Tasks: " << pThis->
fTasks.size()
257 pThis->
DbgLog(
"waiting for a task");
267 pThis->
DbgLog(
"done waiting for tasks");
273 if (!pThis->
fTasks.empty()) {
275 task = pThis->
fTasks.front();
278 pThis->
DbgLog(
"get the task");
283 pThis->
DbgLog(
"done Check <<<<");
288 pThis->
DbgLog(
"Run the task");
300 pThis->
DbgLog(
"Done Running the task");
307 pThis->
DbgLog(
"**** DONE ***");
313 threads_array_t::const_iterator iter = pThis->
fThreads.begin();
314 threads_array_t::const_iterator iter_end = pThis->
fThreads.end();
315 for (; iter != iter_end; ++iter)
TCondition * fThreadNeeded
TThreadPool(size_t threadsCount, bool needDbg=false)
TCondition * fThreadAvailable
TCondition * fAllTasksDone
static void * Executor(void *arg)
TThreadPoolTask< aTask, aParam > task_t
TThreadPoolTaskImp< aTask, aParam > task_t
static Long_t SelfId()
Static method returning the id for the current thread.
Int_t Run(void *arg=0)
Start the thread.
Int_t Wait()
Wait to be signaled.
static void * JoinHelper(void *arg)
void PushTask(typename TThreadPoolTask< aTask, aParam >::task_t &task, aParam param)
const TNonCopyable & operator=(const TNonCopyable &)
static bool IsThreadActive(TThread *pThread)
std::vector< TThread * > threads_array_t
size_t SuccessfulTasks() const
Long_t Join(void **ret=0)
Join this thread.
std::queue< task_t * > taskqueue_t
size_t IdleThreads() const
static void * Monitor(void *arg)
TThread * fThreadJoinHelper
TMutex fMutexAllTasksDone
void DbgLog(const std::string &msg)
R__EXTERN C unsigned int sleep(unsigned int seconds)
void Stop(bool processRemainingJobs=false)
size_t TasksCount() const
TThreadPoolTask(task_t &task, aParam ¶m)