| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Attributes | List of all members
ThreadPoolSvc Class Reference

`#include <src/ThreadPoolSvc.h>`

Inheritance diagram for ThreadPoolSvc:
[legend]
Collaboration diagram for ThreadPoolSvc:
[legend]

## 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::string > | getInterfaceNames () const override
| Implementation of IInterface::getInterfaceNames. More...
| ~extends () override=default
| Virtual destructor. More...
Public Member Functions inherited from Service
const std::string & | name () 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 Property & | getProperty (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 >
Property * | declareProperty (const std::string &name, T &property, const std::string &doc="none") const
| Declare the named property. More...
Property * | declareRemoteProperty (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...
MsgStream & | msgStream () const
| Return an uninitialized MsgStream. More...
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts. More...
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS) More...
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL) More...
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING) More...
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO) More...
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG) More...
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE) More...
MsgStream & | msg () 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< IThreadInitTool > | m_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),
22 m_threadPoolSize(0),
23 m_threadInitTools(this),
24 m_tbbSchedInit(0),
25 m_barrier(0)
26 {
27
28 declareProperty("ThreadInitTools", m_threadInitTools, "ToolHandleArray of IThreadInitTools");
29
30 }
ThreadPoolSvc::m_barrier
boost::barrier * m_barrier
Definition: ThreadPoolSvc.h:48
extends< Service, IThreadPoolSvc >::base_class
extends base_class
Typedef to this class.
Definition: extends.h:14
ThreadPoolSvc::m_threadPoolSize
int m_threadPoolSize
Definition: ThreadPoolSvc.h:40
ThreadPoolSvc::m_init
bool m_init
Definition: ThreadPoolSvc.h:39
ThreadPoolSvc::m_tbbSchedInit
tbb::task_scheduler_init * m_tbbSchedInit
Definition: ThreadPoolSvc.h:46
ThreadPoolSvc::m_threadInitTools
ToolHandleArray< IThreadInitTool > m_threadInitTools
Definition: ThreadPoolSvc.h:42
Service::declareProperty
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 }
ThreadPoolSvc::m_barrier
boost::barrier * m_barrier
Definition: ThreadPoolSvc.h:48
ThreadPoolSvc::m_tbbSchedInit
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 }
ThreadPoolSvc::m_init
bool m_init
Definition: ThreadPoolSvc.h:39
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
StatusCode::SUCCESS
Definition: StatusCode.h:30
endmsg
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
179 std::vector<IThreadInitTool*> tools;
180
181 ToolHandleArray<IThreadInitTool>::const_iterator ito = m_threadInitTools.begin();
182 for ( ; ito != m_threadInitTools.end(); ++ito ) {
183 IThreadInitTool* it = &(**ito);
184 tools.push_back(it);
185 }
186
187 return tools;
188 }
ToolHandleArray
Array of Handles to be used in lieu of vector of naked pointers to tools.
Definition: PropertyMgr.h:24
std::vector::push_back
T push_back(T...args)
GaudiHandleArray::begin
iterator begin()
Definition: GaudiHandle.h:448
std::vector
STL class.
GaudiHandleArray::end
iterator end()
Definition: GaudiHandle.h:452
ThreadPoolSvc::m_threadInitTools
ToolHandleArray< IThreadInitTool > m_threadInitTools
Definition: ThreadPoolSvc.h:42
IThreadInitTool
IThreadInitTool GaudiKernel/IThreadInitTool.h.
Definition: IThreadInitTool.h:18

StatusCode ThreadPoolSvc::initialize | ( |  | ) |
| virtual

Initialise.

Definition at line 47 of file ThreadPoolSvc.cpp.

47 {
48
49 // Initialise mother class (read properties, ...)
50 StatusCode sc(Service::initialize());
51 if (!sc.isSuccess()) {
52 warning () << "Base class could not be initialized" << endmsg;
53 return StatusCode::FAILURE;
54 }
55
56 if (m_threadInitTools.retrieve().isFailure()) {
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 }
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
merge_files.sc
int sc
Definition: merge_files.py:167
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
StatusCode::FAILURE
Definition: StatusCode.h:29
GaudiHandleArray::retrieve
StatusCode retrieve()
Retrieve all tools.
Definition: GaudiHandle.h:517
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiHandleArray::size
size_type size() const
Definition: GaudiHandle.h:472
ThreadPoolSvc::m_threadInitTools
ToolHandleArray< IThreadInitTool > m_threadInitTools
Definition: ThreadPoolSvc.h:42
endmsg
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
96 m_threadPoolSize = poolSize;
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())
124 ThreadInitTask( m_threadInitTools, m_barrier, serviceLocator() );
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;
138 ThreadInitTask theTask(m_threadInitTools, m_barrier, serviceLocator() );
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
150 if (ThreadInitTask::execFailed()) {
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 }
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
ThreadPoolSvc::m_barrier
boost::barrier * m_barrier
Definition: ThreadPoolSvc.h:48
MSG::DEBUG
Definition: IMessageSvc.h:18
ThreadInitTask
Definition: ThreadInitTask.h:14
ThreadPoolSvc::m_threadPoolSize
int m_threadPoolSize
Definition: ThreadPoolSvc.h:40
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
ThreadPoolSvc::m_init
bool m_init
Definition: ThreadPoolSvc.h:39
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
ThreadInitTask::execFailed
static bool execFailed()
Definition: ThreadInitTask.h:28
locker.lock
def lock(file)
Definition: locker.py:16
ThreadPoolSvc::poolSize
virtual int poolSize() const
Definition: ThreadPoolSvc.h:32
ThreadPoolSvc::m_initMutex
tbb::spin_mutex m_initMutex
Definition: ThreadPoolSvc.h:44
ThreadPoolSvc::m_tbbSchedInit
tbb::task_scheduler_init * m_tbbSchedInit
Definition: ThreadPoolSvc.h:46
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
GaudiHandleArray::size
size_type size() const
Definition: GaudiHandle.h:472
ThreadPoolSvc::m_threadInitTools
ToolHandleArray< IThreadInitTool > m_threadInitTools
Definition: ThreadPoolSvc.h:42
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
ana.i
list i
Definition: ana.py:128
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

virtual bool ThreadPoolSvc::isInit | ( |  | ) | const
| inline virtual

Definition at line 33 of file ThreadPoolSvc.h.

33 { return m_init; }
ThreadPoolSvc::m_init
bool m_init
Definition: ThreadPoolSvc.h:39

virtual int ThreadPoolSvc::poolSize | ( |  | ) | const
| inline virtual

Definition at line 32 of file ThreadPoolSvc.h.

32 {return m_threadPoolSize;}
ThreadPoolSvc::m_threadPoolSize
int m_threadPoolSize
Definition: ThreadPoolSvc.h:40

## 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:

- GaudiHive/src/ThreadPoolSvc.h
- GaudiHive/src/ThreadPoolSvc.cpp