]> OCCT Git - occt.git/commitdiff
0031921: Application Framework - reading OCAF data from several threads is not possible
authormpv <mpv@opencascade.com>
Mon, 16 Nov 2020 13:49:23 +0000 (16:49 +0300)
committerbugmaster <bugmaster@opencascade.com>
Sat, 28 Nov 2020 09:36:06 +0000 (12:36 +0300)
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
src/TDF/TDF_LabelNode.hxx

index 63303b2de19eb58a9fe8c552c807c2e153c98a3d..430c03bd82d7b3dc6cdf2626e2a3efaec1dd498d 100644 (file)
  #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 <atomic>
+//! #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<theType> 
+#else
+  #define Standard_ATOMIC(theType) theType
+#endif
+
+
 #endif
index 4be1660e60ea90564fb07e10c09a1182733014ec..244ff7b9376e928528d8e5188fc674e46ce3632b 100644 (file)
 #include <TDF_HAllocator.hxx>
 #include <NCollection_DefineAlloc.hxx>
 
+#ifdef Standard_HASATOMIC
+  #include <atomic>
+#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;