| The Gaudi Framework v32r1 (f65d50dc)

InertMessageSvc.cpp
Go to the documentation of this file.
1 // Include files
2
3 #include "InertMessageSvc.h"
4
5 // ----------------------------------------------------------------------------
6 // Implementation file for class: InertMessageSvc
7 //
8 // 12/02/2013: Danilo Piparo
9 // ----------------------------------------------------------------------------
10 DECLARE_COMPONENT( InertMessageSvc )
11
12 //---------------------------------------------------------------------------
13
14 StatusCode InertMessageSvc::initialize() {
15 StatusCode sc = MessageSvc::initialize(); // must be executed first
16 if ( sc.isFailure() ) return sc; // error printed already by MessageSvc
17
18 info() << "Activating in a separate thread" << endmsg;
19 m_thread = std::thread( &InertMessageSvc::m_activate, this );
20
21 return StatusCode::SUCCESS;
22 }
23
24 //---------------------------------------------------------------------------
25
26 StatusCode InertMessageSvc::InertMessageSvc::finalize() {
27 m_deactivate();
28 m_thread.join();
29 return MessageSvc::finalize(); // must be called after all other actions
30 }
31
32 //---------------------------------------------------------------------------
33
34 void InertMessageSvc::m_activate() {
35 m_isActive = true;
36 std::function<void()> thisMessageAction;
37 while ( m_isActive || !m_messageActionsQueue.empty() ) {
38 m_messageActionsQueue.pop( thisMessageAction );
39 if ( thisMessageAction ) thisMessageAction();
40 }
41 }
42
43 //---------------------------------------------------------------------------
44
45 void InertMessageSvc::m_deactivate() {
46 if ( m_isActive ) {
47 // This would be the last action
48 m_messageActionsQueue.emplace( [this]() { m_isActive = false; } );
49 }
50 }
51
52 //---------------------------------------------------------------------------
59 void InertMessageSvc::reportMessage( const Message& msg, int outputLevel ) {
60 // msg has to be copied as the reference may become invalid by the time it is used
61 m_messageActionsQueue.emplace(
62 [this, m = Message( msg ), outputLevel]() { this->i_reportMessage( m, outputLevel ); } );
63 }
64
65 //---------------------------------------------------------------------------
66
67 void InertMessageSvc::reportMessage( const Message& msg ) {
68 // msg has to be copied as the reference may become invalid by the time it's used
69 m_messageActionsQueue.emplace(
70 [this, m = Message( msg )]() { this->i_reportMessage( m, this->outputLevel( m.getSource() ) ); } );
71 }
72
73 //---------------------------------------------------------------------------
74
75 void InertMessageSvc::reportMessage( const StatusCode& code, const std::string& source ) {
76 // msg has to be copied as the source may become invalid by the time it's used
77 m_messageActionsQueue.emplace( [this, code, s = std::string( source )]() { this->i_reportMessage( code, s ); } );
78 }
79
80 //---------------------------------------------------------------------------
InertMessageSvc
Thread safe extension to the standard MessageSvc.
Definition: InertMessageSvc.h:26
std::function
InertMessageSvc::reportMessage
void reportMessage(const Message &msg) override
Implementation of IMessageSvc::reportMessage()
Definition: InertMessageSvc.cpp:67
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:356
InertMessageSvc.h
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::string
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
InertMessageSvc::m_deactivate
void m_deactivate()
Definition: InertMessageSvc.cpp:45
MessageSvc::initialize
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:106
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:92
InertMessageSvc::m_messageActionsQueue
tbb::concurrent_bounded_queue< std::function< void()> > m_messageActionsQueue
Definition: InertMessageSvc.h:53
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:113
Message
The Message class.
Definition: Message.h:17
MessageSvc::finalize
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:237
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
gaudirun.s
string s
Definition: gaudirun.py:316
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:566
InertMessageSvc::m_activate
void m_activate()
Definition: InertMessageSvc.cpp:34
InertMessageSvc::m_isActive
bool m_isActive
Definition: InertMessageSvc.h:51
std::thread
STL class.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192