| The Gaudi Framework v32r1 (f65d50dc)

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

Special TBB task used by ThreadPoolSvc to wrap execution of IThreadInitTools. More...

`#include <src/ThreadInitTask.h>`

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

## Public Member Functions
| ThreadInitTask (ToolHandleArray< IThreadInitTool > &tools, boost::barrier *b, ISvcLocator *svcLocator, bool terminate=false)
tbb::task * | execute () override
| Execute the task. More...

## Static Public Member Functions
static bool | execFailed ()

## Private Attributes
ToolHandleArray< IThreadInitTool > | m_tools
boost::barrier * | m_barrier = nullptr
SmartIF< ISvcLocator > | m_serviceLocator
bool | m_terminate = false

## Static Private Attributes
static std::atomic< bool > | m_execFailed

## Detailed Description

Special TBB task used by ThreadPoolSvc to wrap execution of IThreadInitTools.

Author
  Charles Leggett

Definition at line 21 of file ThreadInitTask.h.

## Constructor & Destructor Documentation

## ◆ ThreadInitTask()

ThreadInitTask::ThreadInitTask | ( | ToolHandleArray< IThreadInitTool > & | tools,
|  | boost::barrier * | b,
|  | ISvcLocator * | svcLocator,
|  | bool | terminate = `false`
| ) |  |
| inline

Definition at line 26 of file ThreadInitTask.h.

28 : m_tools( tools ), m_barrier( b ), m_serviceLocator( svcLocator ), m_terminate( terminate ){};
ThreadInitTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition: ThreadInitTask.h:42
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
ThreadInitTask::m_tools
ToolHandleArray< IThreadInitTool > m_tools
Definition: ThreadInitTask.h:39
ThreadInitTask::m_terminate
bool m_terminate
Definition: ThreadInitTask.h:43
ThreadInitTask::m_barrier
boost::barrier * m_barrier
Definition: ThreadInitTask.h:41

## Member Function Documentation

## ◆ execFailed()

static bool ThreadInitTask::execFailed | ( |  | ) |
| inline static

Definition at line 36 of file ThreadInitTask.h.

36 { return m_execFailed; }
ThreadInitTask::m_execFailed
static std::atomic< bool > m_execFailed
Definition: ThreadInitTask.h:45

## ◆ execute()

tbb::task * ThreadInitTask::execute | ( |  | ) |
| override

Execute the task.

Will loop over IThreadInitTools and execute each one.

Definition at line 18 of file ThreadInitTask.cpp.

18 {
19
20 SmartIF<IMessageSvc> messageSvc( m_serviceLocator );
21 MsgStream log( messageSvc, "ThreadInitTask" );
22
23 const auto debug = log.level() <= MSG::DEBUG;
24
25 if ( debug )
26 log << MSG::DEBUG << "execute() in thread 0x" << std::hex << pthread_self() << " at " << this << std::dec
27 << " state: " << ( m_terminate ? "terminate" : "initialize" ) << endmsg;
28
29 if ( !m_terminate && Gaudi::Concurrency::ThreadInitDone ) {
30 log << MSG::WARNING << "thread initialization has already been done on thread " << std::hex << pthread_self()
31 << endmsg;
32 }
33
34 if ( m_tools.retrieve().isFailure() ) {
35 log << MSG::ERROR << "unable to retrieve ToolHandleArray " << m_tools << endmsg;
36 m_execFailed = true;
37 } else {
38
39 if ( m_tools.empty() ) {
40 log << MSG::DEBUG << "no entries in Tool Array" << endmsg;
41 if ( !m_terminate ) { Gaudi::Concurrency::ThreadInitDone = true; }
42 } else {
43 if ( debug ) log << MSG::DEBUG << "executing in thread 0x" << std::hex << pthread_self() << std::dec << endmsg;
44
45 // only call terminate for threads that have been initialized
46 if ( m_terminate && !Gaudi::Concurrency::ThreadInitDone ) {
47 log << MSG::INFO << "Not calling terminateThread for thread 0x" << std::hex << pthread_self()
48 << " as it has not been initialized" << endmsg;
49 } else {
50
51 for ( auto& t : m_tools ) {
52 try {
53
54 if ( debug ) log << MSG::DEBUG << "calling IThreadInitTool " << t << endmsg;
55
56 if ( !m_terminate ) {
57 t->initThread();
58 Gaudi::Concurrency::ThreadInitDone = true;
59 } else {
60 t->terminateThread();
61 }
62
63 } catch ( const GaudiException& exc ) {
64 log << MSG::ERROR << "ThreadInitTool " << t << " in thread 0x" << std::hex << pthread_self() << std::dec
65 << " threw GaudiException: " << exc << endmsg;
66 m_execFailed = true;
67 } catch ( const std::exception& exc ) {
68 log << MSG::ERROR << "ThreadInitTool " << t << " in thread 0x" << std::hex << pthread_self() << std::dec
69 << " threw std::exception: " << exc.what() << endmsg;
70 m_execFailed = true;
71 } catch ( ... ) {
72 log << MSG::ERROR << "ThreadInitTool " << t << " in thread 0x" << std::hex << pthread_self() << std::dec
73 << " threw unknown exception" << endmsg;
74 m_execFailed = true;
75 }
76 }
77 }
78
79 m_tools.release().ignore();
80 }
81 }
82
83 if ( m_barrier ) {
84 log << MSG::DEBUG << "waiting at barrier in thread 0x" << std::hex << pthread_self() << std::dec << endmsg;
85 m_barrier->wait();
86 }
87
88 return nullptr;
89 }
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
SmartIF< IMessageSvc >
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
ThreadInitTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition: ThreadInitTask.h:42
ThreadInitTask::m_execFailed
static std::atomic< bool > m_execFailed
Definition: ThreadInitTask.h:45
MSG::DEBUG
Definition: IMessageSvc.h:15
GaudiHandleArray::empty
bool empty() const override
Return whether the list of tools is empty.
Definition: GaudiHandle.h:471
GaudiHandleArray::retrieve
StatusCode retrieve()
Retrieve all tools.
Definition: GaudiHandle.h:498
std::exception::what
T what(T... args)
std::exception
STL class.
ThreadInitTask::m_tools
ToolHandleArray< IThreadInitTool > m_tools
Definition: ThreadInitTask.h:39
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
Gaudi::Concurrency::ThreadInitDone
thread_local bool ThreadInitDone
Definition: ThreadInitTask.cpp:12
ThreadInitTask::m_terminate
bool m_terminate
Definition: ThreadInitTask.h:43
ThreadInitTask::m_barrier
boost::barrier * m_barrier
Definition: ThreadInitTask.h:41
std::hex
T hex(T... args)
MSG::ERROR
Definition: IMessageSvc.h:15
MSG::WARNING
Definition: IMessageSvc.h:15
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
MSG::INFO
Definition: IMessageSvc.h:15
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi.Configuration.log
log
Definition: Configuration.py:13
GaudiHandleArray::release
StatusCode release()
Release all tools.
Definition: GaudiHandle.h:512

## Member Data Documentation

## ◆ m_barrier

boost::barrier* ThreadInitTask::m_barrier = nullptr
| private

Definition at line 41 of file ThreadInitTask.h.

## ◆ m_execFailed

std::atomic< bool > ThreadInitTask::m_execFailed
| static private

Definition at line 45 of file ThreadInitTask.h.

## ◆ m_serviceLocator

SmartIF<ISvcLocator> ThreadInitTask::m_serviceLocator
| private

Definition at line 42 of file ThreadInitTask.h.

## ◆ m_terminate

bool ThreadInitTask::m_terminate = false
| private

Definition at line 43 of file ThreadInitTask.h.

## ◆ m_tools

ToolHandleArray<IThreadInitTool> ThreadInitTask::m_tools
| private

Definition at line 39 of file ThreadInitTask.h.

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

- GaudiHive/src/ThreadInitTask.h
- GaudiHive/src/ThreadInitTask.cpp