The Gaudi Framework  v32r2 (46d42edc)
ThreadPoolSvc Class Reference

A service which initializes a TBB thread pool. More...

#include <src/ThreadPoolSvc.h>

Inheritance diagram for ThreadPoolSvc:
Collaboration diagram for ThreadPoolSvc:

Public Member Functions

 ThreadPoolSvc (const std::string &name, ISvcLocator *svc)
 Constructor. More...
 
StatusCode initialize () override final
 Initialise. More...
 
StatusCode finalize () override final
 Finalise. More...
 
StatusCode initPool (const int &poolSize) override final
 Initialize the thread pool and launch the ThreadInitTasks. More...
 
StatusCode terminatePool () override final
 Terminate the thread pool and launch thread termination tasks. More...
 
int poolSize () const override final
 
virtual bool isInit () const
 
virtual void initThisThread () override
 
- 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...
 
- 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...
 
 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 >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used 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 PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const
 Backward compatibility function for getting the output level. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
const 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...
 

Private Member Functions

StatusCode launchTasks (bool finalize=false)
 Launch tasks to execute the ThreadInitTools. More...
 

Private Attributes

ToolHandleArray< IThreadInitToolm_threadInitTools = {this}
 Handle array of thread init tools. More...
 
bool m_init = false
 Was the thread pool initialized? More...
 
int m_threadPoolSize = 0
 Size of the thread pool allocated. More...
 
tbb::spin_mutex m_initMutex
 Mutex used to protect the initPool and terminatePool methods. More...
 
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
 TBB task scheduler initializer. More...
 
std::unique_ptr< boost::barrier > m_barrier
 Barrier used to synchronization thread init tasks. More...
 
std::unique_ptr< tbb::global_control > m_tbbgc
 TBB global control parameter. More...
 

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
using Factory = Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- 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 PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::Property< int > m_outputLevel {this, "OutputLevel", MSG::NIL, "output level"}
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, " unused"}
 
Gaudi::Property< bool > m_auditorInitialize {this, "AuditInitialize", false, "trigger auditor on initialize()"}
 
Gaudi::Property< bool > m_auditorStart {this, "AuditStart", false, "trigger auditor on start()"}
 
Gaudi::Property< bool > m_auditorStop {this, "AuditStop", false, "trigger auditor on stop()"}
 
Gaudi::Property< bool > m_auditorFinalize {this, "AuditFinalize", false, "trigger auditor on finalize()"}
 
Gaudi::Property< bool > m_auditorReinitialize {this, "AuditReinitialize", false, "trigger auditor on reinitialize()"}
 
Gaudi::Property< bool > m_auditorRestart {this, "AuditRestart", false, "trigger auditor on restart()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

A service which initializes a TBB thread pool.

This service can be configured with an array of IThreadInitTools which will each be invoked concurrently on each worker thread. A ThreadInitTask is created for each thread and given the list of tools. A boost::barrier is used to synchronize the calling of each tool concurrently on all threads at the same time.

Definition at line 28 of file ThreadPoolSvc.h.

Constructor & Destructor Documentation

◆ ThreadPoolSvc()

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

Constructor.

Definition at line 24 of file ThreadPoolSvc.cpp.

24  : extends( name, svcLoc ) {
25  declareProperty( "ThreadInitTools", m_threadInitTools, "ToolHandleArray of IThreadInitTools" );
26 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:56

Member Function Documentation

◆ finalize()

StatusCode ThreadPoolSvc::finalize ( )
finaloverride

Finalise.

Definition at line 55 of file ThreadPoolSvc.cpp.

55  {
56 
57  if ( !m_init ) {
58  warning() << "Looks like the ThreadPoolSvc was created, but thread pool "
59  << "was never initialized" << endmsg;
60  }
61 
62  return StatusCode::SUCCESS;
63 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:59
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ initialize()

StatusCode ThreadPoolSvc::initialize ( )
finaloverride

Initialise.

Definition at line 30 of file ThreadPoolSvc.cpp.

30  {
31 
32  // Initialise mother class (read properties, ...)
34  if ( !sc.isSuccess() ) {
35  warning() << "Base class could not be initialized" << endmsg;
36  return StatusCode::FAILURE;
37  }
38 
40  error() << "Unable to retrieve ThreadInitTools Array" << endmsg;
41 
42  return StatusCode::FAILURE;
43  }
44  if ( m_threadInitTools.size() != 0 ) {
45  info() << "retrieved " << m_threadInitTools.size() << " thread init tools" << endmsg;
46  } else {
47  info() << "no thread init tools attached" << endmsg;
48  }
49 
50  return StatusCode::SUCCESS;
51 }
StatusCode initialize() override
Definition: Service.cpp:60
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
size_type size() const
Definition: GaudiHandle.h:463
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StatusCode retrieve()
Retrieve all tools.
Definition: GaudiHandle.h:494
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:56
bool isFailure() const
Definition: StatusCode.h:130
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ initPool()

StatusCode ThreadPoolSvc::initPool ( const int &  poolSize)
finaloverride

Initialize the thread pool and launch the ThreadInitTasks.

Definition at line 67 of file ThreadPoolSvc.cpp.

67  {
68 
69  tbb::spin_mutex::scoped_lock lock( m_initMutex );
70 
72 
73  if ( msgLevel( MSG::DEBUG ) ) debug() << "ThreadPoolSvc::initPool() poolSize = " << poolSize << endmsg;
74  // There is a problem in the piece of the code below. if
75  // m_threadPoolSize is set to something negative which is < -1,
76  // algorithm below might not behave as expected. For the time being
77  // I've choosen to create the barrier with the default number of
78  // threads created by the task scheduler init assuming that a
79  // negative value will choose automatic thread creation which will
80  // create default number of threads.
81  // SK
82 
83  // -100 prevents the creation of the pool and the scheduler directly
84  // executes the tasks.
85  // -1 means use all available cores
86 
87  if ( -100 != m_threadPoolSize ) {
88  if ( msgLevel( MSG::DEBUG ) ) debug() << "Initialising a thread pool of size " << m_threadPoolSize << endmsg;
89 
90  // Leave -1 in case selected, increment otherwise
91  // - What?
92  int thePoolSize = m_threadPoolSize;
93  if ( thePoolSize >= 0 ) thePoolSize += 1;
94 
95  if ( m_threadPoolSize == -1 ) {
96  // if requested pool size == -1, use number of available cores
97  m_tbbSchedInit = std::make_unique<tbb::task_scheduler_init>();
98  thePoolSize = m_tbbSchedInit->default_num_threads();
99  m_threadPoolSize = thePoolSize;
100  } else if ( m_threadPoolSize >= 0 ) {
101  // Limit the number of threads to requested pool size plus 1
102  m_tbbgc = std::make_unique<tbb::global_control>( global_control::max_allowed_parallelism, thePoolSize );
103  m_tbbSchedInit = std::make_unique<tbb::task_scheduler_init>( thePoolSize );
104  } else {
105  fatal() << "Unexpected ThreadPoolSize \"" << m_threadPoolSize << "\". Allowed negative values are "
106  << "-1 (use all available cores) and -100 (don't use a thread pool)" << endmsg;
107  return StatusCode::FAILURE;
108  }
109 
111 
112  // Create the barrier for task synchronization at termination
113  m_barrier = std::make_unique<boost::barrier>( thePoolSize );
114 
115  } else {
116  // don't use a thread pool
118  m_tbbgc = std::make_unique<tbb::global_control>( global_control::max_allowed_parallelism, 0 );
119  }
120 
121  if ( msgLevel( MSG::DEBUG ) )
122  debug() << "Thread Pool initialization complete. Max task concurrency: "
123  << tbb::global_control::active_value( global_control::max_allowed_parallelism ) << endmsg;
124 
125  m_init = true;
126 
127  return StatusCode::SUCCESS;
128 }
std::unique_ptr< tbb::global_control > m_tbbgc
TBB global control parameter.
Definition: ThreadPoolSvc.h:74
static GAUDI_API void setNumThreads(const std::size_t &nT)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:62
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:59
T lock(T... args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
Definition: ThreadPoolSvc.h:71
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition: ThreadPoolSvc.h:65
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
Definition: ThreadPoolSvc.h:68
int poolSize() const override final
Definition: ThreadPoolSvc.h:45
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ initThisThread()

void GAUDI_NO_SANITIZE_ADDRESS ThreadPoolSvc::initThisThread ( )
overridevirtual

Definition at line 233 of file ThreadPoolSvc.cpp.

233  {
234 
236  // this should never happen
237  error() << "initThisThread triggered, but thread already initialized" << endmsg;
238  throw GaudiException( "initThisThread triggered, but thread already initialized", name(), StatusCode::FAILURE );
239  }
240 
241  boost::barrier* noBarrier = nullptr;
242  ThreadInitTask theTask( m_threadInitTools, noBarrier, serviceLocator(), false );
243  theTask.execute();
244 }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:277
Define general base for Gaudi exception.
Special TBB task used by ThreadPoolSvc to wrap execution of IThreadInitTools.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
thread_local bool ThreadInitDone
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:56
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ isInit()

virtual bool ThreadPoolSvc::isInit ( ) const
inlinevirtual

Definition at line 47 of file ThreadPoolSvc.h.

47 { return m_init; }
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:59

◆ launchTasks()

StatusCode ThreadPoolSvc::launchTasks ( bool  finalize = false)
private

Launch tasks to execute the ThreadInitTools.

Definition at line 152 of file ThreadPoolSvc.cpp.

152  {
153 
154  const std::string taskType = terminate ? "termination" : "initialization";
155 
156  // If we have a thread pool (via a scheduler), then we want to queue
157  // the tasks in TBB to execute on each thread.
158  if ( m_tbbSchedInit ) {
159 
160  // Create one task for each worker thread in the pool
161  for ( int i = 0; i < m_threadPoolSize; ++i ) {
162  if ( msgLevel( MSG::DEBUG ) ) debug() << "creating ThreadInitTask " << i << endmsg;
163  tbb::task* t = new ( tbb::task::allocate_root() )
165 
166  // Queue the task
167  tbb::task::enqueue( *t );
168  this_tbb_thread::sleep( tbb::tick_count::interval_t( .02 ) );
169  }
170 
171  // Now wait for all the workers to reach the barrier
172  if ( msgLevel( MSG::DEBUG ) ) debug() << "waiting at barrier for all ThreadInitTool to finish executing" << endmsg;
173  m_barrier->wait();
174 
175  // Check to make sure all Tools were invoked.
176  // I'm not sure this mechanism is worthwhile.
177  for ( auto& t : m_threadInitTools ) {
178  // Number of threads initialized but not terminated.
179  int numInit = t->nInit();
180  // Expected number based on the type of task.
181  int expectedNumInit = terminate ? 0 : m_threadPoolSize;
182  if ( numInit != expectedNumInit ) {
183  std::ostringstream ost;
184  ost << "not all threads " << ( terminate ? "terminated" : "initialized" ) << " for tool " << t << " : "
185  << t->nInit() << " out of " << m_threadPoolSize << " are currently active.";
186  if ( terminate ) {
187  // it is likely the case that tbb activated new theads
188  // late in the game, and extra initializations were done
189  info() << ost.str() << endmsg;
190  } else {
191  error() << ost.str() << endmsg;
192  return StatusCode::FAILURE;
193  }
194  }
195  }
196 
197  }
198 
199  // In single-threaded mode, there is no scheduler, so we simply call
200  // the task wrapper directly in this thread.
201  else {
202  if ( msgLevel( MSG::DEBUG ) ) debug() << "launching ThreadInitTask " << taskType << "in this thread." << endmsg;
203  boost::barrier* noBarrier = nullptr;
204  ThreadInitTask theTask( m_threadInitTools, noBarrier, serviceLocator(), terminate );
205  theTask.execute();
206  }
207 
208  // Now, we do some error checking
209  if ( ThreadInitTask::execFailed() ) {
210  error() << "a ThreadInitTask failed to execute successfully" << endmsg;
211  return StatusCode::FAILURE;
212  }
213 
214  return StatusCode::SUCCESS;
215 }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:277
Special TBB task used by ThreadPoolSvc to wrap execution of IThreadInitTools.
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:62
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
static bool execFailed()
T str(T... args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
Definition: ThreadPoolSvc.h:71
T get(T... args)
StatusCode terminate() override
Definition: Service.h:51
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
Definition: ThreadPoolSvc.h:68
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
Definition: ThreadPoolSvc.h:56
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ poolSize()

int ThreadPoolSvc::poolSize ( ) const
inlinefinaloverride

Definition at line 45 of file ThreadPoolSvc.h.

45 { return m_threadPoolSize; }
int m_threadPoolSize
Size of the thread pool allocated.
Definition: ThreadPoolSvc.h:62

◆ terminatePool()

StatusCode ThreadPoolSvc::terminatePool ( )
finaloverride

Terminate the thread pool and launch thread termination tasks.

Definition at line 132 of file ThreadPoolSvc.cpp.

132  {
133  tbb::spin_mutex::scoped_lock lock( m_initMutex );
134  if ( msgLevel( MSG::DEBUG ) ) debug() << "ThreadPoolSvc::terminatePool()" << endmsg;
135 
136  if ( !m_init ) {
137  error() << "Trying to terminate uninitialized thread pool!" << endmsg;
138  return StatusCode::FAILURE;
139  }
140 
141  // Launch the termination tasks
142  const bool terminate = true;
143  if ( launchTasks( terminate ).isFailure() ) return StatusCode::FAILURE;
144 
145  if ( msgLevel( MSG::DEBUG ) ) debug() << "Thread pool termination complete!" << endmsg;
146 
147  return StatusCode::SUCCESS;
148 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
bool m_init
Was the thread pool initialized?
Definition: ThreadPoolSvc.h:59
T lock(T... args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
Definition: ThreadPoolSvc.h:65
StatusCode terminate() override
Definition: Service.h:51
constexpr static const auto FAILURE
Definition: StatusCode.h:86
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

Member Data Documentation

◆ m_barrier

std::unique_ptr<boost::barrier> ThreadPoolSvc::m_barrier
private

Barrier used to synchronization thread init tasks.

Definition at line 71 of file ThreadPoolSvc.h.

◆ m_init

bool ThreadPoolSvc::m_init = false
private

Was the thread pool initialized?

Definition at line 59 of file ThreadPoolSvc.h.

◆ m_initMutex

tbb::spin_mutex ThreadPoolSvc::m_initMutex
private

Mutex used to protect the initPool and terminatePool methods.

Definition at line 65 of file ThreadPoolSvc.h.

◆ m_tbbgc

std::unique_ptr<tbb::global_control> ThreadPoolSvc::m_tbbgc
private

TBB global control parameter.

Definition at line 74 of file ThreadPoolSvc.h.

◆ m_tbbSchedInit

std::unique_ptr<tbb::task_scheduler_init> ThreadPoolSvc::m_tbbSchedInit
private

TBB task scheduler initializer.

Definition at line 68 of file ThreadPoolSvc.h.

◆ m_threadInitTools

ToolHandleArray<IThreadInitTool> ThreadPoolSvc::m_threadInitTools = {this}
private

Handle array of thread init tools.

Definition at line 56 of file ThreadPoolSvc.h.

◆ m_threadPoolSize

int ThreadPoolSvc::m_threadPoolSize = 0
private

Size of the thread pool allocated.

Definition at line 62 of file ThreadPoolSvc.h.


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