6 #include "tbb/task_scheduler_init.h"
7 #include "tbb/task_scheduler_observer.h"
9 #include "tbb/tick_count.h"
10 #include "tbb/tbb_thread.h"
23 m_threadInitTools(this),
28 declareProperty(
"ThreadInitTools", m_threadInitTools,
"ToolHandleArray of IThreadInitTools");
37 delete m_tbbSchedInit;
52 warning () <<
"Base class could not be initialized" <<
endmsg;
56 if (m_threadInitTools.retrieve().isFailure()) {
57 error() <<
"Unable to retrieve ThreadInitTools Array"
62 if (m_threadInitTools.size() != 0) {
63 info() <<
"retrieved " << m_threadInitTools.size() <<
" thread init tools"
66 info() <<
"no thread init tools attached"
81 warning() <<
"Looks like the ThreadPoolSvc was created, but thread pool was never initialized"
94 tbb::spin_mutex::scoped_lock
lock( m_initMutex );
96 m_threadPoolSize = poolSize;
99 debug() <<
"ThreadPoolSvc::initPool() poolSize = " << poolSize <<
endmsg;
103 if (-100 != m_threadPoolSize){
105 debug() <<
"Initialising a ThreadPool thread pool of size " << m_threadPoolSize
108 int thePoolSize=m_threadPoolSize;
111 m_tbbSchedInit =
new tbb::task_scheduler_init (thePoolSize);
114 if (m_threadInitTools.size() > 0) {
116 debug() <<
"creating barrier of size " << m_threadPoolSize + 1 <<
endmsg;
117 m_barrier =
new boost::barrier( m_threadPoolSize + 1 );
120 for (
int i=0;
i<m_threadPoolSize; ++
i) {
122 debug() <<
"creating ThreadInitTask " <<
i <<
endmsg;
123 tbb::task* t =
new(tbb::task::allocate_root())
126 tbb::task::enqueue( *t );
127 this_tbb_thread::sleep(tbb::tick_count::interval_t(.1));
133 debug() <<
"Thread pool size is one. Pool not initialised." <<
endmsg;
135 if (m_threadInitTools.size() > 0) {
137 debug() <<
"doing ThreadInitTask init in this thread" <<
endmsg;
138 ThreadInitTask theTask(m_threadInitTools, m_barrier, serviceLocator() );
146 debug() <<
"waiting at barrier for all ThreadInitTool to finish executing" <<
endmsg;
151 error() <<
"a ThreadInitTask failed to execute successfully" <<
endmsg;
156 for (
auto t : m_threadInitTools) {
157 if (t->nInit() != (
unsigned int)m_threadPoolSize && m_threadPoolSize != -100) {
158 error() <<
" not all threads initialized for tool " << t <<
" : "
159 << t->nInit() <<
" out of " << m_threadPoolSize
166 debug() <<
" Thread Pool initialization complete!" <<
endmsg;
182 for ( ; ito != m_threadInitTools.
end(); ++ito ) {
StatusCode initialize() override
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
~ThreadPoolSvc()
Destructor.
bool isSuccess() const
Test for a status code of SUCCESS.
virtual StatusCode initPool(const int &poolSize)
This class is used for returning status codes from appropriate routines.
#define DECLARE_SERVICE_FACTORY(x)
virtual tbb::task * execute()
virtual StatusCode initialize()
Initialise.
virtual std::vector< IThreadInitTool * > getThreadInitTools() const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual StatusCode finalize()
Finalise.