The Gaudi Framework
master (934d2c3c)
Toggle main menu visibility
Loading...
Searching...
No Matches
ThreadInitTask.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
12
// Local includes
13
#include "
ThreadInitTask.h
"
14
15
// Framework includes
16
#include <
GaudiKernel/IMessageSvc.h
>
17
#include <
GaudiKernel/ISvcLocator.h
>
18
#include <
GaudiKernel/IThreadInitTool.h
>
19
#include <
GaudiKernel/MsgStream.h
>
20
#include <
GaudiKernel/SmartIF.h
>
21
#include <
GaudiKernel/ToolHandle.h
>
22
23
// STL includes
24
#include <
atomic
>
25
#include <
ios
>
26
#include <pthread.h>
27
#include <
thread
>
28
29
namespace
Gaudi
{
30
namespace
Concurrency
{
31
thread_local
bool
ThreadInitDone
{
false
};
32
}
33
}
// namespace Gaudi
34
35
std::atomic<bool>
ThreadInitTask::m_execFailed
(
false
);
36
37
void
ThreadInitTask::operator()
()
const
{
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
48
if
( !
m_terminate
&&
Gaudi::Concurrency::ThreadInitDone
) {
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
;
55
if
( !
m_terminate
) {
Gaudi::Concurrency::ThreadInitDone
=
true
; }
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
60
if
(
m_terminate
&& !
Gaudi::Concurrency::ThreadInitDone
) {
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();
72
Gaudi::Concurrency::ThreadInitDone
=
true
;
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
}
IMessageSvc.h
ISvcLocator.h
IThreadInitTool.h
MsgStream.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
SmartIF.h
ThreadInitTask.h
ToolHandle.h
atomic
ios
thread
log
complex< _Tp > log(const complex< _Tp > &)
std::hex
ios_base & hex(ios_base &__base)
std::dec
ios_base & dec(ios_base &__base)
std::atomic
std::exception
vector::empty
constexpr bool empty() const noexcept
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
GaudiException::what
const char * what() const override
method from std::exception
Definition
GaudiException.h:108
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition
MsgStream.h:29
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition
SmartIF.h:28
ThreadInitTask::m_barrier
std::barrier * m_barrier
Definition
ThreadInitTask.h:52
ThreadInitTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition
ThreadInitTask.h:53
ThreadInitTask::m_tools
std::vector< IThreadInitTool * > m_tools
Definition
ThreadInitTask.h:50
ThreadInitTask::m_execFailed
static std::atomic< bool > m_execFailed
Definition
ThreadInitTask.h:56
ThreadInitTask::m_terminate
bool m_terminate
Definition
ThreadInitTask.h:54
ThreadInitTask::operator()
void operator()() const
Execute the task.
Definition
ThreadInitTask.cpp:37
Gaudi::Concurrency
Definition
AlgTask.h:33
Gaudi::Concurrency::ThreadInitDone
bool ThreadInitDone
Definition
ThreadInitTask.cpp:31
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
MSG::WARNING
@ WARNING
Definition
IMessageSvc.h:22
MSG::DEBUG
@ DEBUG
Definition
IMessageSvc.h:22
MSG::ERROR
@ ERROR
Definition
IMessageSvc.h:22
MSG::INFO
@ INFO
Definition
IMessageSvc.h:22
GaudiHive
src
ThreadInitTask.cpp
Generated on
for The Gaudi Framework by
1.18.0