The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
InertMessageSvc.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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_deactivate();
27 m_thread.join();
28 return MessageSvc::finalize(); // must be called after all other actions
29}
30
32 m_isActive = true;
33 std::function<void()> thisMessageAction;
34 while ( m_isActive || !m_messageActionsQueue.empty() ) {
35 m_messageActionsQueue.pop( thisMessageAction );
36 if ( thisMessageAction ) thisMessageAction();
37 }
38}
39
41 if ( m_isActive ) {
42 // This would be the last action
43 m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
44 }
45}
46
54 // msg has to be copied as the reference may become invalid by the time it is used
56 [this, m = Message( msg ), outputLevel]() { this->i_reportMessage( m, outputLevel ); } );
57}
58
60 // msg has to be copied as the reference may become invalid by the time it's used
62 [this, m = Message( msg )]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
63}
64
65void InertMessageSvc::reportMessage( const StatusCode& code, std::string_view source ) {
66 // msg has to be copied as the source may become invalid by the time it's used
67 m_messageActionsQueue.emplace( [this, code, s = std::string{ source }]() { this->i_reportMessage( code, s ); } );
68}
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::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