Skip to content
Snippets Groups Projects
Commit f394175d authored by Nils Krumnack's avatar Nils Krumnack
Browse files

protect AsgMessagingForward in AthenaMT

In MT the MsgStream object is thread-local.  So instead of retrieving
the MsgStream& object once, this will retrieve it on every use.
parent 359a3dba
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "AsgMessaging/MsgStream.h" #include "AsgMessaging/MsgStream.h"
#include "AsgMessaging/MsgStreamMacros.h" #include "AsgMessaging/MsgStreamMacros.h"
#include <functional>
namespace asg namespace asg
{ {
/// \brief base class to forward messages to another class /// \brief base class to forward messages to another class
...@@ -65,15 +67,21 @@ namespace asg ...@@ -65,15 +67,21 @@ namespace asg
// //
/// \brief the message stream we use /// \brief the message stream we use
///
/// This used to be a simple pointer to the `MsgStream` itself,
/// but in AthenaMT the actual object used is local to the thread.
/// So instead of pointing to it directly we are now using a
/// function to look it up, which will get the thread-local
/// object.
private: private:
MsgStream *m_msg {nullptr}; std::function<MsgStream& ()> m_msg;
}; };
template<typename T> AsgMessagingForward :: template<typename T> AsgMessagingForward ::
AsgMessagingForward( T *owner ) AsgMessagingForward( T *owner )
: m_msg (&owner->msg()) : m_msg ([owner] () -> MsgStream& {return owner->msg();})
{} {}
} }
......
/* /*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/ */
...@@ -9,9 +10,10 @@ namespace asg ...@@ -9,9 +10,10 @@ namespace asg
{ {
bool AsgMessagingForward::msgLvl( const MSG::Level lvl ) const bool AsgMessagingForward::msgLvl( const MSG::Level lvl ) const
{ {
if (m_msg->level() <= lvl) MsgStream& msg = m_msg();
if (msg.level() <= lvl)
{ {
(*m_msg) << lvl; msg << lvl;
return true; return true;
} else } else
{ {
...@@ -21,12 +23,13 @@ namespace asg ...@@ -21,12 +23,13 @@ namespace asg
MsgStream& AsgMessagingForward::msg() const MsgStream& AsgMessagingForward::msg() const
{ {
return *m_msg; return m_msg();
} }
MsgStream& AsgMessagingForward::msg( const MSG::Level lvl ) const MsgStream& AsgMessagingForward::msg( const MSG::Level lvl ) const
{ {
(*m_msg) << lvl; MsgStream& msg = m_msg ();
return *m_msg; msg << lvl;
return msg;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment