The Gaudi Framework
master (f31105fd)
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Typedefs
a
b
c
d
e
f
h
i
l
m
o
p
r
s
t
u
v
w
x
Enumerations
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
y
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Enumerations
a
c
d
e
f
i
l
m
n
o
p
q
r
s
t
v
Enumerator
a
b
c
d
e
f
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Properties
Related Functions
:
a
b
c
d
e
g
h
i
m
o
p
r
s
t
v
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
_
b
c
e
f
g
h
i
l
m
n
o
p
r
s
t
u
z
Variables
a
b
c
d
e
g
h
i
m
o
p
q
r
s
t
v
x
Typedefs
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
w
Enumerations
Enumerator
c
e
f
p
u
v
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
ThreadInitTask.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2024 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
#include "
ThreadInitTask.h
"
12
#include <
GaudiKernel/IMessageSvc.h
>
13
#include <
GaudiKernel/ISvcLocator.h
>
14
#include <
GaudiKernel/IThreadInitTool.h
>
15
#include <
GaudiKernel/MsgStream.h
>
16
#include <
GaudiKernel/SmartIF.h
>
17
#include <
GaudiKernel/ToolHandle.h
>
18
#include <thread>
19
20
namespace
Gaudi
{
21
namespace
Concurrency {
22
thread_local
bool
ThreadInitDone
{
false
};
23
}
24
}
// namespace Gaudi
25
26
std::atomic<bool>
ThreadInitTask::m_execFailed
(
false
);
27
28
void
ThreadInitTask::operator()
()
const
{
29
30
SmartIF<IMessageSvc>
messageSvc(
m_serviceLocator
);
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
39
if
( !
m_terminate
&&
Gaudi::Concurrency::ThreadInitDone
) {
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
45
ToolHandleArray<IThreadInitTool>
tools(
m_tools
);
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
;
54
if
( !
m_terminate
) {
Gaudi::Concurrency::ThreadInitDone
=
true
; }
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
59
if
(
m_terminate
&& !
Gaudi::Concurrency::ThreadInitDone
) {
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();
71
Gaudi::Concurrency::ThreadInitDone
=
true
;
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
}
MSG::DEBUG
@ DEBUG
Definition:
IMessageSvc.h:25
IThreadInitTool.h
std::exception
STL class.
Gaudi.Configuration.log
log
Definition:
Configuration.py:28
MSG::INFO
@ INFO
Definition:
IMessageSvc.h:25
GaudiHandleArray::retrieve
StatusCode retrieve()
Retrieve all tools.
Definition:
GaudiHandle.h:512
GaudiException
Definition:
GaudiException.h:32
Gaudi::Concurrency::ThreadInitDone
thread_local bool ThreadInitDone
Definition:
ThreadInitTask.cpp:22
GaudiHandleArray::empty
bool empty() const override
Return whether the list of tools is empty.
Definition:
GaudiHandle.h:485
MSG::WARNING
@ WARNING
Definition:
IMessageSvc.h:25
ThreadInitTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition:
ThreadInitTask.h:49
ThreadInitTask.h
IMessageSvc.h
GaudiHandleArray::release
StatusCode release()
Release all tools.
Definition:
GaudiHandle.h:526
std::hex
T hex(T... args)
bug_34121.t
t
Definition:
bug_34121.py:31
SmartIF.h
ThreadInitTask::m_barrier
boost::barrier * m_barrier
Definition:
ThreadInitTask.h:48
ToolHandleArray< IThreadInitTool >
ThreadInitTask::operator()
void operator()() const
Execute the task.
Definition:
ThreadInitTask.cpp:28
SmartIF< IMessageSvc >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition:
MsgStream.h:202
std::atomic< bool >
MsgStream
Definition:
MsgStream.h:33
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition:
__init__.py:1
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition:
StatusCode.h:140
StatusCode::isFailure
bool isFailure() const
Definition:
StatusCode.h:130
ToolHandle.h
MSG::ERROR
@ ERROR
Definition:
IMessageSvc.h:25
ISvcLocator.h
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)
MsgStream.h
GaudiHive
src
ThreadInitTask.cpp
Generated on Mon Apr 7 2025 16:26:21 for The Gaudi Framework by
1.8.18