ThreadPoolSvc Class Reference

#include <src/ThreadPoolSvc.h>

Inheritance diagram for ThreadPoolSvc:
Collaboration diagram for ThreadPoolSvc:

Public Member Functions

 ThreadPoolSvc (const std::string &name, ISvcLocator *svc)
 Constructor. More...
 
 ~ThreadPoolSvc ()
 Destructor. More...
 
virtual StatusCode initialize ()
 Initialise. More...
 
virtual StatusCode finalize ()
 Finalise. More...
 
virtual StatusCode initPool (const int &poolSize)
 
virtual int poolSize () const
 
virtual bool isInit () const
 
virtual std::vector< IThreadInitTool * > getThreadInitTools () const
 
- Public Member Functions inherited from extends< Service, IThreadPoolSvc >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
StatusCode setProperty (const Property &p) override
 
StatusCode setProperty (const std::string &s) override
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 
StatusCode getProperty (Property *p) const override
 
const PropertygetProperty (const std::string &name) const override
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 
const std::vector< Property * > & getProperties () const override
 
bool hasProperty (const std::string &name) const override
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
template<class T >
StatusCode declarePrivateTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Private tool. More...
 
template<class T >
StatusCode declarePublicTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Public tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Attributes

bool m_init
 
int m_threadPoolSize
 
ToolHandleArray< IThreadInitToolm_threadInitTools
 
tbb::spin_mutex m_initMutex
 
tbb::task_scheduler_init * m_tbbSchedInit
 
boost::barrier * m_barrier
 

Additional Inherited Members

- Public Types inherited from extends< Service, IThreadPoolSvc >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel = MSG::NIL
 Service output level. More...
 
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 

Detailed Description

Definition at line 15 of file ThreadPoolSvc.h.

Constructor & Destructor Documentation

ThreadPoolSvc::ThreadPoolSvc ( const std::string name,
ISvcLocator svc 
)

Constructor.

Definition at line 19 of file ThreadPoolSvc.cpp.

19  :
20  base_class(name,svcLoc),
21  m_init(false),
23  m_threadInitTools(this),
24  m_tbbSchedInit(0),
25  m_barrier(0)
26 {
27 
28  declareProperty("ThreadInitTools", m_threadInitTools, "ToolHandleArray of IThreadInitTools");
29 
30 }
boost::barrier * m_barrier
Definition: ThreadPoolSvc.h:48
extends base_class
Typedef to this class.
Definition: extends.h:14
tbb::task_scheduler_init * m_tbbSchedInit
Definition: ThreadPoolSvc.h:46
ToolHandleArray< IThreadInitTool > m_threadInitTools
Definition: ThreadPoolSvc.h:42
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
ThreadPoolSvc::~ThreadPoolSvc ( )

Destructor.

Definition at line 34 of file ThreadPoolSvc.cpp.

34  {
35 
36  if (m_tbbSchedInit)
37  delete m_tbbSchedInit;
38 
39  if (m_barrier)
40  delete m_barrier;
41 
42 }
boost::barrier * m_barrier
Definition: ThreadPoolSvc.h:48
tbb::task_scheduler_init * m_tbbSchedInit
Definition: ThreadPoolSvc.h:46

Member Function Documentation

StatusCode ThreadPoolSvc::finalize ( )
virtual

Finalise.

Definition at line 78 of file ThreadPoolSvc.cpp.

78  {
79 
80  if (!m_init) {
81  warning() << "Looks like the ThreadPoolSvc was created, but thread pool was never initialized"
82  << endmsg;
83  }
84 
85  return StatusCode::SUCCESS;
86 
87 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::vector< IThreadInitTool * > ThreadPoolSvc::getThreadInitTools ( ) const
virtual

Definition at line 177 of file ThreadPoolSvc.cpp.

177  {
178 
180 
182  for ( ; ito != m_threadInitTools.end(); ++ito ) {
183  IThreadInitTool* it = &(**ito);
184  tools.push_back(it);
185  }
186 
187  return tools;
188 }
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:24
T push_back(T...args)
iterator begin()
Definition: GaudiHandle.h:448
STL class.
iterator end()
Definition: GaudiHandle.h:452
ToolHandleArray< IThreadInitTool > m_threadInitTools
Definition: ThreadPoolSvc.h:42
IThreadInitTool GaudiKernel/IThreadInitTool.h.
StatusCode ThreadPoolSvc::initialize ( )
virtual

Initialise.

Definition at line 47 of file ThreadPoolSvc.cpp.

47  {
48 
49  // Initialise mother class (read properties, ...)
51  if (!sc.isSuccess()) {
52  warning () << "Base class could not be initialized" << endmsg;
53  return StatusCode::FAILURE;
54  }
55 
57  error() << "Unable to retrieve ThreadInitTools Array"
58  << endmsg;
59 
60  return StatusCode::FAILURE;
61  } else {
62  if (m_threadInitTools.size() != 0) {
63  info() << "retrieved " << m_threadInitTools.size() << " thread init tools"
64  << endmsg;
65  } else {
66  info() << "no thread init tools attached"
67  << endmsg;
68  }
69  }
70 
71  return StatusCode::SUCCESS;
72 
73 }
StatusCode initialize() override
Definition: Service.cpp:68
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
StatusCode retrieve()
Retrieve all tools.
Definition: GaudiHandle.h:517
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
size_type size() const
Definition: GaudiHandle.h:472
ToolHandleArray< IThreadInitTool > m_threadInitTools
Definition: ThreadPoolSvc.h:42
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode ThreadPoolSvc::initPool ( const int &  poolSize)
virtual

Definition at line 92 of file ThreadPoolSvc.cpp.

92  {
93 
94  tbb::spin_mutex::scoped_lock lock( m_initMutex );
95 
97 
98  if (msgLevel(MSG::DEBUG))
99  debug() << "ThreadPoolSvc::initPool() poolSize = " << poolSize << endmsg;
100 
101  // -100 prevents the creation of the pool and the scheduler directly executes
102  // the tasks.
103  if (-100 != m_threadPoolSize){
104  if (msgLevel(MSG::DEBUG))
105  debug() << "Initialising a ThreadPool thread pool of size " << m_threadPoolSize
106  << endmsg;
107  // Leave -1 in case selected, increment otherwise
108  int thePoolSize=m_threadPoolSize;
109  if (thePoolSize!=-1)
110  thePoolSize+=1;
111  m_tbbSchedInit = new tbb::task_scheduler_init (thePoolSize);
112 
113  // execute the Thread Init Tools if there are any, and wait at barrier
114  if (m_threadInitTools.size() > 0) {
115  if (msgLevel(MSG::DEBUG))
116  debug() << "creating barrier of size " << m_threadPoolSize + 1 << endmsg;
117  m_barrier = new boost::barrier( m_threadPoolSize + 1 );
118 
119  // create ThreadInitTasks, wait until all have executed
120  for (int i=0; i<m_threadPoolSize; ++i) {
121  if (msgLevel(MSG::DEBUG))
122  debug() << "creating ThreadInitTask " << i << endmsg;
123  tbb::task* t = new(tbb::task::allocate_root())
125 
126  tbb::task::enqueue( *t );
127  this_tbb_thread::sleep(tbb::tick_count::interval_t(.1));
128  }
129  }
130 
131  } else {
132  if (msgLevel(MSG::DEBUG))
133  debug() << "Thread pool size is one. Pool not initialised." << endmsg;
134 
135  if (m_threadInitTools.size() > 0) {
136  if (msgLevel(MSG::DEBUG))
137  debug() << "doing ThreadInitTask init in this thread" << endmsg;
139  theTask.execute();
140  }
141 
142  }
143 
144  if (m_barrier) {
145  if (msgLevel(MSG::DEBUG))
146  debug() << "waiting at barrier for all ThreadInitTool to finish executing" << endmsg;
147  m_barrier->wait();
148  }
149 
151  error() << "a ThreadInitTask failed to execute successfully" << endmsg;
152  return StatusCode::FAILURE;
153  }
154 
155  // check to make sure all Tools were initialized
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
160  << endmsg;
161  return StatusCode::FAILURE;
162  }
163  }
164 
165  if (msgLevel(MSG::DEBUG))
166  debug() << " Thread Pool initialization complete!" << endmsg;
167 
168  m_init = true;
169 
170  return StatusCode::SUCCESS;
171 
172 }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
boost::barrier * m_barrier
Definition: ThreadPoolSvc.h:48
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
static bool execFailed()
def lock(file)
Definition: locker.py:16
virtual int poolSize() const
Definition: ThreadPoolSvc.h:32
tbb::spin_mutex m_initMutex
Definition: ThreadPoolSvc.h:44
tbb::task_scheduler_init * m_tbbSchedInit
Definition: ThreadPoolSvc.h:46
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
size_type size() const
Definition: GaudiHandle.h:472
ToolHandleArray< IThreadInitTool > m_threadInitTools
Definition: ThreadPoolSvc.h:42
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual bool ThreadPoolSvc::isInit ( ) const
inlinevirtual

Definition at line 33 of file ThreadPoolSvc.h.

33 { return m_init; }
virtual int ThreadPoolSvc::poolSize ( ) const
inlinevirtual

Definition at line 32 of file ThreadPoolSvc.h.

32 {return m_threadPoolSize;}

Member Data Documentation

boost::barrier* ThreadPoolSvc::m_barrier
private

Definition at line 48 of file ThreadPoolSvc.h.

bool ThreadPoolSvc::m_init
private

Definition at line 39 of file ThreadPoolSvc.h.

tbb::spin_mutex ThreadPoolSvc::m_initMutex
private

Definition at line 44 of file ThreadPoolSvc.h.

tbb::task_scheduler_init* ThreadPoolSvc::m_tbbSchedInit
private

Definition at line 46 of file ThreadPoolSvc.h.

ToolHandleArray<IThreadInitTool> ThreadPoolSvc::m_threadInitTools
private

Definition at line 42 of file ThreadPoolSvc.h.

int ThreadPoolSvc::m_threadPoolSize
private

Definition at line 40 of file ThreadPoolSvc.h.


The documentation for this class was generated from the following files: