From b84b672185520e52a25d63b4487f285a068abc34 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 16 Nov 2020 16:49:23 +0300 Subject: [PATCH] 0031921: Application Framework - reading OCAF data from several threads is not possible Make myLastFoundChild field of TDF_LabelNode that can be changed during accessing to different sub-labels in different threads as atomic (only for newer versions of compilers which support this "atomic"). Added definition of Standard_ATOMIC macro to the Standard_Macro.hxx --- src/Standard/Standard_Macro.hxx | 15 +++++++++++++++ src/TDF/TDF_LabelNode.hxx | 20 ++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Standard/Standard_Macro.hxx b/src/Standard/Standard_Macro.hxx index 63303b2de1..430c03bd82 100644 --- a/src/Standard/Standard_Macro.hxx +++ b/src/Standard/Standard_Macro.hxx @@ -281,4 +281,19 @@ #endif #endif +//! @def Standard_ATOMIC +//! Definition of Standard_ATOMIC for C++11 or visual studio that supports it. +//! Before usage there must be "atomic" included in the following way: +//! #ifdef Standard_HASATOMIC +//! #include +//! #endif +#if (defined(__cplusplus) && __cplusplus >= 201100L) || (defined(_MSC_VER) && _MSC_VER >= 1800) || \ + (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) + #define Standard_HASATOMIC + #define Standard_ATOMIC(theType) std::atomic +#else + #define Standard_ATOMIC(theType) theType +#endif + + #endif diff --git a/src/TDF/TDF_LabelNode.hxx b/src/TDF/TDF_LabelNode.hxx index 4be1660e60..244ff7b937 100644 --- a/src/TDF/TDF_LabelNode.hxx +++ b/src/TDF/TDF_LabelNode.hxx @@ -22,6 +22,10 @@ #include #include +#ifdef Standard_HASATOMIC + #include +#endif + class TDF_Attribute; class TDF_AttributeIterator; class TDF_ChildIterator; @@ -160,15 +164,15 @@ class TDF_LabelNode { // Private Fields // -------------------------------------------------------------------------- - TDF_LabelNodePtr myFather; - TDF_LabelNodePtr myBrother; - TDF_LabelNodePtr myFirstChild; - TDF_LabelNodePtr myLastFoundChild; //jfa 10.01.2003 - Standard_Integer myTag; - Standard_Integer myFlags; // Flags & Depth - Handle(TDF_Attribute) myFirstAttribute; + TDF_LabelNodePtr myFather; + TDF_LabelNodePtr myBrother; + TDF_LabelNodePtr myFirstChild; + Standard_ATOMIC(TDF_LabelNodePtr) myLastFoundChild; //jfa 10.01.2003 + Standard_Integer myTag; + Standard_Integer myFlags; // Flags & Depth + Handle(TDF_Attribute) myFirstAttribute; #ifdef KEEP_LOCAL_ROOT - TDF_Data * myData; + TDF_Data * myData; #endif #ifdef OCCT_DEBUG TCollection_AsciiString myDebugEntry;