The Gaudi Framework master (934d2c3c)
Loading...
Searching...
No Matches
ThreadInitTask Class Reference

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

#include <ThreadInitTask.h>

Collaboration diagram for ThreadInitTask:

Public Member Functions

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

Static Public Member Functions

static bool execFailed ()

Private Attributes

std::vector< IThreadInitTool * > m_tools
std::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 31 of file ThreadInitTask.h.

Constructor & Destructor Documentation

◆ ThreadInitTask()

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

Definition at line 34 of file ThreadInitTask.h.

36 : m_barrier( b ), m_serviceLocator( svcLocator ), m_terminate( terminate ) {
37 m_tools.reserve( tools.size() );
38 for ( auto& tool : tools ) { m_tools.push_back( tool.get() ); }
39 }
constexpr void push_back(const value_type &__x)
constexpr void reserve(size_type __n)
size_type size() const
std::barrier * m_barrier
SmartIF< ISvcLocator > m_serviceLocator
std::vector< IThreadInitTool * > m_tools

Member Function Documentation

◆ execFailed()

bool ThreadInitTask::execFailed ( )
inlinestatic

Definition at line 47 of file ThreadInitTask.h.

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

◆ operator()()

void ThreadInitTask::operator() ( ) const

Execute the task.

Will loop over IThreadInitTools and execute each one.

Definition at line 37 of file ThreadInitTask.cpp.

37 {
38
39 SmartIF<IMessageSvc> messageSvc( m_serviceLocator );
40 MsgStream log( messageSvc, "ThreadInitTask" );
41
42 const auto debug = log.level() <= MSG::DEBUG;
43
44 if ( debug )
45 log << MSG::DEBUG << "execute() in thread 0x" << std::hex << pthread_self() << " at " << this << std::dec
46 << " state: " << ( m_terminate ? "terminate" : "initialize" ) << endmsg;
47
49 log << MSG::WARNING << "thread initialization has already been done on thread " << std::hex << pthread_self()
50 << endmsg;
51 }
52
53 if ( m_tools.empty() ) {
54 log << MSG::DEBUG << "no entries in Tool Array" << endmsg;
56 } else {
57 if ( debug ) log << MSG::DEBUG << "executing in thread 0x" << std::hex << pthread_self() << std::dec << endmsg;
58
59 // only call terminate for threads that have been initialized
61 log << MSG::INFO << "Not calling terminateThread for thread 0x" << std::hex << pthread_self()
62 << " as it has not been initialized" << endmsg;
63 } else {
64
65 for ( auto* tool : m_tools ) {
66 try {
67
68 if ( debug ) log << MSG::DEBUG << "calling IThreadInitTool " << tool->name() << endmsg;
69
70 if ( !m_terminate ) {
71 tool->initThread();
73 } else {
74 tool->terminateThread();
75 }
76
77 } catch ( const GaudiException& exc ) {
78 log << MSG::ERROR << "ThreadInitTool " << tool->name() << " in thread 0x" << std::hex << pthread_self()
79 << std::dec << " threw GaudiException: " << exc << endmsg;
80 m_execFailed = true;
81 } catch ( const std::exception& exc ) {
82 log << MSG::ERROR << "ThreadInitTool " << tool->name() << " in thread 0x" << std::hex << pthread_self()
83 << std::dec << " threw std::exception: " << exc.what() << endmsg;
84 m_execFailed = true;
85 } catch ( ... ) {
86 log << MSG::ERROR << "ThreadInitTool " << tool->name() << " in thread 0x" << std::hex << pthread_self()
87 << std::dec << " threw unknown exception" << endmsg;
88 m_execFailed = true;
89 }
90 }
91 }
92 }
93
94 if ( m_barrier ) {
95 log << MSG::DEBUG << "waiting at barrier in thread 0x" << std::hex << pthread_self() << std::dec << endmsg;
96 m_barrier->arrive_and_wait();
97 }
98}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
ios_base & hex(ios_base &__base)
ios_base & dec(ios_base &__base)
virtual const char * what() const noexcept
constexpr bool empty() const noexcept
@ WARNING
Definition IMessageSvc.h:22
@ DEBUG
Definition IMessageSvc.h:22
@ ERROR
Definition IMessageSvc.h:22
@ INFO
Definition IMessageSvc.h:22

Member Data Documentation

◆ m_barrier

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

Definition at line 52 of file ThreadInitTask.h.

◆ m_execFailed

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

Definition at line 56 of file ThreadInitTask.h.

◆ m_serviceLocator

SmartIF<ISvcLocator> ThreadInitTask::m_serviceLocator
private

Definition at line 53 of file ThreadInitTask.h.

◆ m_terminate

bool ThreadInitTask::m_terminate = false
private

Definition at line 54 of file ThreadInitTask.h.

◆ m_tools

std::vector<IThreadInitTool*> ThreadInitTask::m_tools
private

Definition at line 50 of file ThreadInitTask.h.


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