The Gaudi Framework  master (37c0b60a)
InertMessageSvc.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 files
12 
13 #include "InertMessageSvc.h"
14 
15 // ----------------------------------------------------------------------------
16 // Implementation file for class: InertMessageSvc
17 //
18 // 12/02/2013: Danilo Piparo
19 // ----------------------------------------------------------------------------
21 
22 //---------------------------------------------------------------------------
23 
24 StatusCode InertMessageSvc::initialize() {
25  StatusCode sc = MessageSvc::initialize(); // must be executed first
26  if ( sc.isFailure() ) return sc; // error printed already by MessageSvc
27 
28  info() << "Activating in a separate thread" << endmsg;
29  m_thread = std::thread( &InertMessageSvc::m_activate, this );
30 
31  return StatusCode::SUCCESS;
32 }
33 
34 //---------------------------------------------------------------------------
35 
36 StatusCode InertMessageSvc::InertMessageSvc::finalize() {
37  m_deactivate();
38  m_thread.join();
39  return MessageSvc::finalize(); // must be called after all other actions
40 }
41 
42 //---------------------------------------------------------------------------
43 
45  m_isActive = true;
46  std::function<void()> thisMessageAction;
47  while ( m_isActive || !m_messageActionsQueue.empty() ) {
48  m_messageActionsQueue.pop( thisMessageAction );
49  if ( thisMessageAction ) thisMessageAction();
50  }
51 }
52 
53 //---------------------------------------------------------------------------
54 
56  if ( m_isActive ) {
57  // This would be the last action
58  m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
59  }
60 }
61 
62 //---------------------------------------------------------------------------
69 void InertMessageSvc::reportMessage( const Message& msg, int outputLevel ) {
70  // msg has to be copied as the reference may become invalid by the time it is used
71  m_messageActionsQueue.emplace(
72  [this, m = Message( msg ), outputLevel]() { this->i_reportMessage( m, outputLevel ); } );
73 }
74 
75 //---------------------------------------------------------------------------
76 
78  // msg has to be copied as the reference may become invalid by the time it's used
79  m_messageActionsQueue.emplace(
80  [this, m = Message( msg )]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
81 }
82 
83 //---------------------------------------------------------------------------
84 
85 void InertMessageSvc::reportMessage( const StatusCode& code, std::string_view source ) {
86  // msg has to be copied as the source may become invalid by the time it's used
87  m_messageActionsQueue.emplace( [this, code, s = std::string{ source }]() { this->i_reportMessage( code, s ); } );
88 }
89 
90 //---------------------------------------------------------------------------
std::string
STL class.
InertMessageSvc::m_isActive
bool m_isActive
Definition: InertMessageSvc.h:61
gaudirun.s
string s
Definition: gaudirun.py:346
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:344
std::function
InertMessageSvc
Definition: InertMessageSvc.h:36
StatusCode
Definition: StatusCode.h:65
std::thread
STL class.
Message
Definition: Message.h:26
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
InertMessageSvc::m_deactivate
void m_deactivate()
Definition: InertMessageSvc.cpp:55
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
InertMessageSvc.h
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:544
MessageSvc::finalize
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:225
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
InertMessageSvc::m_activate
void m_activate()
Definition: InertMessageSvc.cpp:44
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
ProduceConsume.Message
Message
Definition: ProduceConsume.py:110
MessageSvc::initialize
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:101
InertMessageSvc::m_messageActionsQueue
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
Definition: InertMessageSvc.h:63
InertMessageSvc::reportMessage
void reportMessage(const Message &msg) override
Implementation of IMessageSvc::reportMessage()
Definition: InertMessageSvc.cpp:77