The Gaudi Framework  master (594c33fa)
ThreadInitTask Class Reference

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

#include </builds/gaudi/Gaudi/GaudiHive/src/ThreadInitTask.h>

Collaboration diagram for ThreadInitTask:

Public Member Functions

 ThreadInitTask (ToolHandleArray< IThreadInitTool > &tools, boost::barrier *b, ISvcLocator *svcLocator, bool terminate=false)
 
void operator() () const
 Execute the task. More...
 

Static Public Member Functions

static bool execFailed ()
 

Private Attributes

ToolHandleArray< IThreadInitToolm_tools
 
boost::barrier * m_barrier = nullptr
 
SmartIF< ISvcLocatorm_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 30 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 33 of file ThreadInitTask.h.

35  : m_tools( tools ), m_barrier( b ), m_serviceLocator( svcLocator ), m_terminate( terminate ){};

Member Function Documentation

◆ execFailed()

static bool ThreadInitTask::execFailed ( )
inlinestatic

Definition at line 43 of file ThreadInitTask.h.

43 { return m_execFailed; }

◆ operator()()

void ThreadInitTask::operator() ( ) const

Execute the task.

Will loop over IThreadInitTools and execute each one.

Definition at line 28 of file ThreadInitTask.cpp.

28  {
29 
31  MsgStream log( messageSvc, "ThreadInitTask" );
32 
33  const auto debug = log.level() <= MSG::DEBUG;
34 
35  if ( debug )
36  log << MSG::DEBUG << "execute() in thread 0x" << std::hex << pthread_self() << " at " << this << std::dec
37  << " state: " << ( m_terminate ? "terminate" : "initialize" ) << endmsg;
38 
40  log << MSG::WARNING << "thread initialization has already been done on thread " << std::hex << pthread_self()
41  << endmsg;
42  }
43 
44  // copy the tools array not to violate the const contract of the method
46 
47  if ( tools.retrieve().isFailure() ) {
48  log << MSG::ERROR << "unable to retrieve ToolHandleArray " << tools << endmsg;
49  m_execFailed = true;
50  } else {
51 
52  if ( tools.empty() ) {
53  log << MSG::DEBUG << "no entries in Tool Array" << endmsg;
55  } else {
56  if ( debug ) log << MSG::DEBUG << "executing in thread 0x" << std::hex << pthread_self() << std::dec << endmsg;
57 
58  // only call terminate for threads that have been initialized
60  log << MSG::INFO << "Not calling terminateThread for thread 0x" << std::hex << pthread_self()
61  << " as it has not been initialized" << endmsg;
62  } else {
63 
64  for ( auto& t : tools ) {
65  try {
66 
67  if ( debug ) log << MSG::DEBUG << "calling IThreadInitTool " << t << endmsg;
68 
69  if ( !m_terminate ) {
70  t->initThread();
72  } else {
73  t->terminateThread();
74  }
75 
76  } catch ( const GaudiException& exc ) {
77  log << MSG::ERROR << "ThreadInitTool " << t << " in thread 0x" << std::hex << pthread_self() << std::dec
78  << " threw GaudiException: " << exc << endmsg;
79  m_execFailed = true;
80  } catch ( const std::exception& exc ) {
81  log << MSG::ERROR << "ThreadInitTool " << t << " in thread 0x" << std::hex << pthread_self() << std::dec
82  << " threw std::exception: " << exc.what() << endmsg;
83  m_execFailed = true;
84  } catch ( ... ) {
85  log << MSG::ERROR << "ThreadInitTool " << t << " in thread 0x" << std::hex << pthread_self() << std::dec
86  << " threw unknown exception" << endmsg;
87  m_execFailed = true;
88  }
89  }
90  }
91 
92  tools.release().ignore();
93  }
94  }
95 
96  if ( m_barrier ) {
97  log << MSG::DEBUG << "waiting at barrier in thread 0x" << std::hex << pthread_self() << std::dec << endmsg;
98  m_barrier->wait();
99  }
100 }

Member Data Documentation

◆ m_barrier

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

Definition at line 48 of file ThreadInitTask.h.

◆ m_execFailed

std::atomic< bool > ThreadInitTask::m_execFailed
staticprivate

Definition at line 52 of file ThreadInitTask.h.

◆ m_serviceLocator

SmartIF<ISvcLocator> ThreadInitTask::m_serviceLocator
private

Definition at line 49 of file ThreadInitTask.h.

◆ m_terminate

bool ThreadInitTask::m_terminate = false
private

Definition at line 50 of file ThreadInitTask.h.

◆ m_tools

ToolHandleArray<IThreadInitTool> ThreadInitTask::m_tools
private

Definition at line 46 of file ThreadInitTask.h.


The documentation for this class was generated from the following files:
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
std::exception
STL class.
Gaudi.Configuration.log
log
Definition: Configuration.py:28
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
GaudiException
Definition: GaudiException.h:31
Gaudi::Concurrency::ThreadInitDone
thread_local bool ThreadInitDone
Definition: ThreadInitTask.cpp:22
MSG::WARNING
@ WARNING
Definition: IMessageSvc.h:25
ThreadInitTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition: ThreadInitTask.h:49
std::hex
T hex(T... args)
bug_34121.t
t
Definition: bug_34121.py:31
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
ThreadInitTask::m_barrier
boost::barrier * m_barrier
Definition: ThreadInitTask.h:48
ToolHandleArray< IThreadInitTool >
SmartIF< IMessageSvc >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
MsgStream
Definition: MsgStream.h:34
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
ThreadInitTask::m_terminate
bool m_terminate
Definition: ThreadInitTask.h:50
ThreadInitTask::m_tools
ToolHandleArray< IThreadInitTool > m_tools
Definition: ThreadInitTask.h:46
ThreadInitTask::m_execFailed
static std::atomic< bool > m_execFailed
Definition: ThreadInitTask.h:52
std::exception::what
T what(T... args)