The Gaudi Framework  v32r2 (46d42edc)
ThreadInitTask Class Reference

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

#include <src/ThreadInitTask.h>

Inheritance diagram for ThreadInitTask:
Collaboration diagram for ThreadInitTask:

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< 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 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 ){};
SmartIF< ISvcLocator > m_serviceLocator
GAUDI_API ISvcLocator * svcLocator()
ToolHandleArray< IThreadInitTool > m_tools
boost::barrier * m_barrier

Member Function Documentation

◆ execFailed()

static bool ThreadInitTask::execFailed ( )
inlinestatic

Definition at line 36 of file ThreadInitTask.h.

36 { return m_execFailed; }
static std::atomic< bool > m_execFailed

◆ 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 
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 
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;
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
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();
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 
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 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Define general base for Gaudi exception.
SmartIF< ISvcLocator > m_serviceLocator
static std::atomic< bool > m_execFailed
bool empty() const override
Return whether the list of tools is empty.
Definition: GaudiHandle.h:467
StatusCode retrieve()
Retrieve all tools.
Definition: GaudiHandle.h:494
T what(T... args)
STL class.
ToolHandleArray< IThreadInitTool > m_tools
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
thread_local bool ThreadInitDone
boost::barrier * m_barrier
T hex(T... args)
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
StatusCode release()
Release all tools.
Definition: GaudiHandle.h:508

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
staticprivate

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: