]> OCCT Git - occt.git/commitdiff
0033058: JT Import - perform XT translation in multiple threads
authoratychini <atychini@opencascade.com>
Tue, 5 Jul 2022 15:39:08 +0000 (18:39 +0300)
committersmoskvin <smoskvin@opencascade.com>
Tue, 6 Sep 2022 17:10:58 +0000 (20:10 +0300)
Creating mutex for proper parallel processing.

src/ShapeProcess/ShapeProcess_Context.cxx

index a010e8382b6084fda623928bff4a13ddbf50a0cc..7bce89474f4f3c8c0d3b28243c44468620b1b288 100644 (file)
@@ -20,6 +20,7 @@
 #include <ShapeProcess_Context.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
+#include <Standard_Mutex.hxx>
 #include <Standard_Type.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_HAsciiString.hxx>
@@ -27,6 +28,8 @@
 #include <sys/stat.h>
 IMPLEMENT_STANDARD_RTTIEXT(ShapeProcess_Context,Standard_Transient)
 
+static Standard_Mutex THE_SHAPE_PROCESS_MUTEX;
+
 //=======================================================================
 //function : ShapeProcess_Context
 //purpose  : 
@@ -73,6 +76,9 @@ Standard_Boolean ShapeProcess_Context::Init (const Standard_CString file,
 
 Handle(Resource_Manager) ShapeProcess_Context::LoadResourceManager (const Standard_CString name)
 {
+  // Mutex is needed because we are initializing and changing static variables here, so
+  // without mutex it leads to race condition.
+  Standard_Mutex::Sentry aLock(&THE_SHAPE_PROCESS_MUTEX);
   // Optimisation of loading resource file: file is load only once
   // and reloaded only if file date has changed
   static Handle(Resource_Manager) sRC;
@@ -127,7 +133,10 @@ Handle(Resource_Manager) ShapeProcess_Context::LoadResourceManager (const Standa
       sUMtime = aUMtime;
     }
   }
-  return sRC;
+  // Creating copy of sRC for thread safety of Resource_Manager variables
+  // We should return copy because calling of Resource_Manager::SetResource() for one object
+  // in multiple threads causes race condition
+  return new Resource_Manager(*sRC);
 }
 
 //=======================================================================