1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0023920: Change use of static variables in Message package to prevent data races in Shape Healing

This commit is contained in:
Roman Lygin 2013-04-21 09:28:54 +04:00
parent d18bedc711
commit fa523cddc5

View File

@ -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;
}