The Gaudi Framework  master (905e8f18)
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
14
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
23}
24
25StatusCode 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
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
42 if ( m_isActive ) {
43 // This would be the last action
44 m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
45 }
46}
47
55 // msg has to be copied as the reference may become invalid by the time it is used
57 [this, m = Message( msg ), outputLevel]() { this->i_reportMessage( m, outputLevel ); } );
58}
59
61 // msg has to be copied as the reference may become invalid by the time it's used
63 [this, m = Message( msg )]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
64}
65
66void 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}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Thread safe extension to the standard MessageSvc.
void reportMessage(const Message &msg) override
Implementation of IMessageSvc::reportMessage()
StatusCode initialize() override
Initialization of the service.
std::atomic< bool > m_isActive
std::thread m_thread
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
The Message class.
Definition Message.h:25
int outputLevel() const override
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
StatusCode initialize() override
StatusCode finalize() override
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99