diff --git a/Control/AthToolSupport/AsgMessaging/AsgMessaging/AsgMessagingForward.h b/Control/AthToolSupport/AsgMessaging/AsgMessaging/AsgMessagingForward.h index 03918739c1d09531fde47bb01df327c28ab625df..89bcba6d8f080c274838a493c0b448a5a8eac7aa 100644 --- a/Control/AthToolSupport/AsgMessaging/AsgMessaging/AsgMessagingForward.h +++ b/Control/AthToolSupport/AsgMessaging/AsgMessaging/AsgMessagingForward.h @@ -12,6 +12,8 @@ #include "AsgMessaging/MsgStream.h" #include "AsgMessaging/MsgStreamMacros.h" +#include <functional> + namespace asg { /// \brief base class to forward messages to another class @@ -65,15 +67,21 @@ namespace asg // /// \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: - MsgStream *m_msg {nullptr}; + std::function<MsgStream& ()> m_msg; }; template<typename T> AsgMessagingForward :: AsgMessagingForward( T *owner ) - : m_msg (&owner->msg()) + : m_msg ([owner] () -> MsgStream& {return owner->msg();}) {} } diff --git a/Control/AthToolSupport/AsgMessaging/Root/AsgMessagingForward.cxx b/Control/AthToolSupport/AsgMessaging/Root/AsgMessagingForward.cxx index 9dea64e00c7283f2a72da85e1c0c366956ce3def..1b17e4cb97dca9d8b07a38f8ec7f91d53969cf01 100644 --- a/Control/AthToolSupport/AsgMessaging/Root/AsgMessagingForward.cxx +++ b/Control/AthToolSupport/AsgMessaging/Root/AsgMessagingForward.cxx @@ -1,3 +1,4 @@ + /* Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ @@ -9,9 +10,10 @@ namespace asg { 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; } else { @@ -21,12 +23,13 @@ namespace asg MsgStream& AsgMessagingForward::msg() const { - return *m_msg; + return m_msg(); } MsgStream& AsgMessagingForward::msg( const MSG::Level lvl ) const { - (*m_msg) << lvl; - return *m_msg; + MsgStream& msg = m_msg (); + msg << lvl; + return msg; } }