From fa523cddc56212ac7d6a1a424b0d86b3e1c7f6e7 Mon Sep 17 00:00:00 2001 From: Roman Lygin Date: Sun, 21 Apr 2013 09:28:54 +0400 Subject: [PATCH] 0023920: Change use of static variables in Message package to prevent data races in Shape Healing --- src/Message/Message_MsgFile.cxx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Message/Message_MsgFile.cxx b/src/Message/Message_MsgFile.cxx index 8d5e5c577f..4eb0aafea1 100755 --- a/src/Message/Message_MsgFile.cxx +++ b/src/Message/Message_MsgFile.cxx @@ -349,11 +349,19 @@ const TCollection_ExtendedString &Message_MsgFile::Msg (const TCollection_AsciiS return aDataMap.Find (theKeyword); // if not found, generate error message - static const TCollection_ExtendedString aDefPrefix ("Unknown message invoked with the keyword: "); + // to minimize risk of data races when running concurrently, set the static variables + // only if they are empty; this gives a possibility to enforce calling this method + // upfront to initialize these variables and only read access them afterwards. However + // theKeyword is no longer appended. aDefPrefix remained unchanged to not break some + // logs which might expect the previous value + static const TCollection_ExtendedString aDefPrefix ("Unknown message invoked with the keyword"); static const TCollection_AsciiString aPrefixCode ("Message_Msg_BadKeyword"); static TCollection_ExtendedString aFailureMessage; - if (aDataMap.IsBound (aPrefixCode)) - aFailureMessage = aDataMap.Find (aPrefixCode) + " " + theKeyword; - else aFailureMessage = aDefPrefix + theKeyword; + if (aFailureMessage.Length() == 0) { + if (aDataMap.IsBound (aPrefixCode)) + aFailureMessage = aDataMap.Find (aPrefixCode); + else + aFailureMessage = aDefPrefix; + } return aFailureMessage; } -- 2.20.1