The Gaudi Framework
master (9f3f8895)
Toggle main menu visibility
Loading...
Searching...
No Matches
InertMessageSvc.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 "
InertMessageSvc.h
"
12
13
DECLARE_COMPONENT
(
InertMessageSvc
)
14
15
StatusCode
InertMessageSvc
::
initialize
() {
16
StatusCode
sc =
MessageSvc::initialize
();
// must be executed first
17
if
( sc.
isFailure
() )
return
sc;
// error printed already by MessageSvc
18
19
info
() <<
"Activating in a separate thread"
<<
endmsg
;
20
m_thread
= std::thread( &
InertMessageSvc::m_activate
,
this
);
21
22
return
StatusCode::SUCCESS
;
23
}
24
25
StatusCode
InertMessageSvc::InertMessageSvc::finalize() {
26
m_messageActionsQueue.emplace( [
this
] { m_suppress =
false
; } );
27
m_deactivate();
28
m_thread.join();
29
return
MessageSvc::finalize
();
// must be called after all other actions
30
}
31
32
void
InertMessageSvc::m_activate
() {
33
m_isActive
=
true
;
34
std::function<void()> thisMessageAction;
35
while
(
m_isActive
|| !
m_messageActionsQueue
.empty() ) {
36
m_messageActionsQueue
.pop( thisMessageAction );
37
if
( thisMessageAction ) thisMessageAction();
38
}
39
}
40
41
void
InertMessageSvc::m_deactivate
() {
42
if
(
m_isActive
) {
43
// This would be the last action
44
m_messageActionsQueue
.emplace( [
this
]() {
m_isActive
=
false
; } );
45
}
46
}
47
54
void
InertMessageSvc::reportMessage
(
const
Message
&
msg
,
int
outputLevel
) {
55
// msg has to be copied as the reference may become invalid by the time it is used
56
m_messageActionsQueue
.emplace(
57
[
this
, m =
Message
(
msg
),
outputLevel
]() { this->
i_reportMessage
( m,
outputLevel
); } );
58
}
59
60
void
InertMessageSvc::reportMessage
(
const
Message
&
msg
) {
61
// msg has to be copied as the reference may become invalid by the time it's used
62
m_messageActionsQueue
.emplace(
63
[
this
, m =
Message
(
msg
)]() { this->
i_reportMessage
( m, this->
outputLevel
( m.getSource() ) ); } );
64
}
65
66
void
InertMessageSvc::reportMessage
(
const
StatusCode
& code, std::string_view source ) {
67
// msg has to be copied as the source may become invalid by the time it's used
68
m_messageActionsQueue
.emplace( [
this
, code, s = std::string{ source }]() { this->
i_reportMessage
( code, s ); } );
69
}
InertMessageSvc.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:124
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:115
InertMessageSvc
Thread safe extension to the standard MessageSvc.
Definition
InertMessageSvc.h:32
InertMessageSvc::reportMessage
void reportMessage(const Message &msg) override
Implementation of IMessageSvc::reportMessage().
Definition
InertMessageSvc.cpp:60
InertMessageSvc::initialize
StatusCode initialize() override
Initialization of the service.
Definition
InertMessageSvc.cpp:15
InertMessageSvc::m_isActive
std::atomic< bool > m_isActive
Definition
InertMessageSvc.h:56
InertMessageSvc::m_thread
std::thread m_thread
Definition
InertMessageSvc.h:66
InertMessageSvc::m_messageActionsQueue
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
Definition
InertMessageSvc.h:64
InertMessageSvc::m_activate
void m_activate()
Definition
InertMessageSvc.cpp:32
InertMessageSvc::m_deactivate
void m_deactivate()
Definition
InertMessageSvc.cpp:41
Message
The Message class.
Definition
Message.h:25
MessageSvc::outputLevel
int outputLevel() const override
Definition
MessageSvc.cpp:434
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition
MessageSvc.cpp:311
MessageSvc::initialize
StatusCode initialize() override
Definition
MessageSvc.cpp:90
MessageSvc::finalize
StatusCode finalize() override
Definition
MessageSvc.cpp:199
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
GaudiCoreSvc
src
MessageSvc
InertMessageSvc.cpp
Generated on
for The Gaudi Framework by
1.17.0