The Gaudi Framework
master (bdbe7744)
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
#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
if
(
m_tools
.empty() ) {
45
log <<
MSG::DEBUG
<<
"no entries in Tool Array"
<<
endmsg
;
46
if
( !
m_terminate
) {
Gaudi::Concurrency::ThreadInitDone
=
true
; }
47
}
else
{
48
if
( debug ) log <<
MSG::DEBUG
<<
"executing in thread 0x"
<< std::hex << pthread_self() << std::dec <<
endmsg
;
49
50
// only call terminate for threads that have been initialized
51
if
(
m_terminate
&& !
Gaudi::Concurrency::ThreadInitDone
) {
52
log <<
MSG::INFO
<<
"Not calling terminateThread for thread 0x"
<< std::hex << pthread_self()
53
<<
" as it has not been initialized"
<<
endmsg
;
54
}
else
{
55
56
for
(
auto
* tool :
m_tools
) {
57
try
{
58
59
if
( debug ) log <<
MSG::DEBUG
<<
"calling IThreadInitTool "
<< tool->name() <<
endmsg
;
60
61
if
( !
m_terminate
) {
62
tool->initThread();
63
Gaudi::Concurrency::ThreadInitDone
=
true
;
64
}
else
{
65
tool->terminateThread();
66
}
67
68
}
catch
(
const
GaudiException
& exc ) {
69
log <<
MSG::ERROR
<<
"ThreadInitTool "
<< tool->name() <<
" in thread 0x"
<< std::hex << pthread_self()
70
<< std::dec <<
" threw GaudiException: "
<< exc <<
endmsg
;
71
m_execFailed
=
true
;
72
}
catch
(
const
std::exception& exc ) {
73
log <<
MSG::ERROR
<<
"ThreadInitTool "
<< tool->name() <<
" in thread 0x"
<< std::hex << pthread_self()
74
<< std::dec <<
" threw std::exception: "
<< exc.
what
() <<
endmsg
;
75
m_execFailed
=
true
;
76
}
catch
( ... ) {
77
log <<
MSG::ERROR
<<
"ThreadInitTool "
<< tool->name() <<
" in thread 0x"
<< std::hex << pthread_self()
78
<< std::dec <<
" threw unknown exception"
<<
endmsg
;
79
m_execFailed
=
true
;
80
}
81
}
82
}
83
}
84
85
if
(
m_barrier
) {
86
log <<
MSG::DEBUG
<<
"waiting at barrier in thread 0x"
<< std::hex << pthread_self() << std::dec <<
endmsg
;
87
m_barrier
->wait();
88
}
89
}
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
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
boost::barrier * m_barrier
Definition
ThreadInitTask.h:49
ThreadInitTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition
ThreadInitTask.h:50
ThreadInitTask::m_tools
std::vector< IThreadInitTool * > m_tools
Definition
ThreadInitTask.h:47
ThreadInitTask::m_execFailed
static std::atomic< bool > m_execFailed
Definition
ThreadInitTask.h:53
ThreadInitTask::m_terminate
bool m_terminate
Definition
ThreadInitTask.h:51
ThreadInitTask::operator()
void operator()() const
Execute the task.
Definition
ThreadInitTask.cpp:28
Gaudi::Concurrency
Definition
AlgTask.h:30
Gaudi::Concurrency::ThreadInitDone
bool ThreadInitDone
Definition
ThreadInitTask.cpp:22
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.17.0