]> OCCT Git - occt.git/commitdiff
Coding - Replace Standard_Mutex with std::mutex and migrate to RAII locks (#766)
authorPasukhin Dmitry <dpasukhi@opencascade.com>
Mon, 3 Nov 2025 16:44:08 +0000 (16:44 +0000)
committerGitHub <noreply@github.com>
Mon, 3 Nov 2025 16:44:08 +0000 (16:44 +0000)
- Replace legacy Standard_Mutex usage across many modules with std::mutex.
- Include <mutex> where needed and remove <Standard_Mutex.hxx> includes.
- Replace Standard_Mutex::Sentry / explicit Lock/Unlock with std::lock_guard or std::unique_lock.
- Convert optional/heap mutex holders to std::unique_ptr<std::mutex> and adapt locking accordingly.
- Simplify several singleton initializations (remove manual double-checked locking where safe).
- Use thread_local for per-thread flags instead of ad-hoc mutex protection.
- Fix BVH_BuildQueue Fetch logic to preserve thread counters and wasBusy handling.
- Remove obsolete TopTools_MutexForShapeProvider sources and update FILES.cmake.

This modernizes mutex usage, reduces dependency on custom mutex types and improves clarity of locking patterns.

95 files changed:
src/ApplicationFramework/TKCDF/CDF/CDF_StoreList.cxx
src/ApplicationFramework/TKLCAF/TDF/TDF_DerivedAttribute.cxx
src/DataExchange/TKDE/DE/DE_ConfigurationNode.cxx
src/DataExchange/TKDE/DE/DE_PluginHolder.hxx
src/DataExchange/TKDE/DE/DE_Wrapper.cxx
src/DataExchange/TKDE/DE/DE_Wrapper.hxx
src/DataExchange/TKDEGLTF/RWGltf/RWGltf_CafReader.cxx
src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Controller.cxx
src/DataExchange/TKDESTEP/STEPControl/STEPControl_Controller.cxx
src/DataExchange/TKDESTEP/STEPControl/STEPControl_Reader.cxx
src/DataExchange/TKDESTEP/STEPEdit/STEPEdit.cxx
src/DataExchange/TKDESTEP/STEPSelections/STEPSelections_SelectGSCurves.cxx
src/DataExchange/TKDESTEP/STEPSelections/STEPSelections_SelectInstances.cxx
src/DataExchange/TKDESTEP/StepFile/StepFile_Read.cxx
src/DataExchange/TKDESTEP/StepSelect/StepSelect_StepType.cxx
src/DataExchange/TKDESTEP/StepToTopoDS/StepToTopoDS_TranslateEdgeLoop.cxx
src/DataExchange/TKDEVRML/VrmlData/VrmlData_Scene.cxx
src/DataExchange/TKDEVRML/VrmlData/VrmlData_Scene.hxx
src/DataExchange/TKRWMesh/RWMesh/RWMesh_TriangulationReader.cxx
src/DataExchange/TKRWMesh/RWMesh/RWMesh_TriangulationReader.hxx
src/DataExchange/TKXSBase/Interface/Interface_Category.cxx
src/DataExchange/TKXSBase/XSAlgo/XSAlgo_AlgoContainer.cxx
src/DataExchange/TKXSBase/XSControl/XSControl_TransferWriter.cxx
src/DataExchange/TKXSBase/XSControl/XSControl_WorkSession.cxx
src/Draw/TKDCAF/DNaming/DNaming_ModelingCommands.cxx
src/Draw/TKDraw/Draw/Draw_ProgressIndicator.hxx
src/Draw/TKQADraw/QABugs/QABugs_20.cxx
src/Draw/TKViewerTest/ViewerTest/ViewerTest_ContinuousRedrawer.cxx
src/Draw/TKViewerTest/ViewerTest/ViewerTest_ContinuousRedrawer.hxx
src/Draw/TKXSDRAWIGES/XSDRAWIGES/XSDRAWIGES.cxx
src/Draw/TKXSDRAWSTL/XSDRAWSTL/XSDRAWSTL.cxx
src/FoundationClasses/TKMath/BVH/BVH_BuildQueue.cxx
src/FoundationClasses/TKMath/BVH/BVH_BuildQueue.hxx
src/FoundationClasses/TKMath/BVH/BVH_QueueBuilder.hxx
src/FoundationClasses/TKernel/Message/Message_MsgFile.cxx
src/FoundationClasses/TKernel/Message/Message_ProgressIndicator.hxx
src/FoundationClasses/TKernel/Message/Message_Report.cxx
src/FoundationClasses/TKernel/Message/Message_Report.hxx
src/FoundationClasses/TKernel/NCollection/NCollection_HeapAllocator.cxx
src/FoundationClasses/TKernel/NCollection/NCollection_IncAllocator.cxx
src/FoundationClasses/TKernel/NCollection/NCollection_IncAllocator.hxx
src/FoundationClasses/TKernel/OSD/OSD_Environment.cxx
src/FoundationClasses/TKernel/OSD/OSD_Parallel_Threads.cxx
src/FoundationClasses/TKernel/OSD/OSD_ThreadPool.cxx
src/FoundationClasses/TKernel/OSD/OSD_ThreadPool.hxx
src/FoundationClasses/TKernel/OSD/OSD_signal.cxx
src/FoundationClasses/TKernel/Standard/Standard_ErrorHandler.cxx
src/FoundationClasses/TKernel/Standard/Standard_ErrorHandler.hxx
src/FoundationClasses/TKernel/Standard/Standard_MMgrOpt.cxx
src/FoundationClasses/TKernel/Standard/Standard_MMgrOpt.hxx
src/FoundationClasses/TKernel/Standard/Standard_StackTrace.cxx
src/FoundationClasses/TKernel/Standard/Standard_Type.cxx
src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_2.cxx
src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_3.cxx
src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_4.cxx
src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_5.cxx
src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_6.cxx
src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_PaveFiller_7.cxx
src/ModelingAlgorithms/TKBO/BOPAlgo/BOPAlgo_RemoveFeatures.cxx
src/ModelingAlgorithms/TKBO/BOPTools/BOPTools_Parallel.hxx
src/ModelingAlgorithms/TKMesh/IMeshTools/IMeshTools_ModelAlgo.hxx
src/ModelingAlgorithms/TKShHealing/ShapeFix/ShapeFix_Wire_1.cxx
src/ModelingAlgorithms/TKShHealing/ShapeProcess/ShapeProcess_Context.cxx
src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck_Analyzer.cxx
src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck_Edge.cxx
src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck_Face.cxx
src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck_Result.cxx
src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck_Result.hxx
src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck_Shell.cxx
src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck_Vertex.cxx
src/ModelingAlgorithms/TKTopAlgo/BRepCheck/BRepCheck_Wire.cxx
src/ModelingAlgorithms/TKTopAlgo/BRepExtrema/BRepExtrema_DistShapeShape.cxx
src/ModelingData/TKBRep/BinTools/BinTools_ShapeReader.cxx
src/ModelingData/TKBRep/BinTools/BinTools_ShapeWriter.cxx
src/ModelingData/TKBRep/TopTools/FILES.cmake
src/ModelingData/TKBRep/TopTools/TopTools_MutexForShapeProvider.cxx [deleted file]
src/ModelingData/TKBRep/TopTools/TopTools_MutexForShapeProvider.hxx [deleted file]
src/ModelingData/TKG3d/Geom/Geom_BSplineSurface_1.cxx
src/Visualization/TKService/Aspect/Aspect_VKeySet.cxx
src/Visualization/TKService/Aspect/Aspect_VKeySet.hxx
src/Visualization/TKService/Graphic3d/Graphic3d_MediaTexture.cxx
src/Visualization/TKService/Graphic3d/Graphic3d_MediaTexture.hxx
src/Visualization/TKService/Graphic3d/Graphic3d_MediaTextureSet.cxx
src/Visualization/TKService/Graphic3d/Graphic3d_MediaTextureSet.hxx
src/Visualization/TKService/Media/Media_PlayerContext.cxx
src/Visualization/TKService/Media/Media_PlayerContext.hxx
src/Visualization/TKV3d/AIS/AIS_ViewController.cxx
src/Visualization/TKV3d/AIS/AIS_ViewController.hxx
src/Visualization/TKV3d/Select3D/Select3D_SensitivePrimitiveArray.hxx
src/Visualization/TKV3d/SelectMgr/SelectMgr_BVHThreadPool.cxx
src/Visualization/TKV3d/SelectMgr/SelectMgr_BVHThreadPool.hxx
src/Visualization/TKV3d/StdPrs/StdPrs_BRepFont.cxx
src/Visualization/TKV3d/StdPrs/StdPrs_BRepFont.hxx
src/Visualization/TKV3d/StdPrs/StdPrs_BRepTextBuilder.cxx
src/Visualization/TKV3d/StdPrs/StdPrs_WFShape.cxx

index 55279c6aa2516030cb81e3955d7fc13dcc9007fa..0dd24bbdb1c23dc7037b6349af4cdd6f82f42fcf 100644 (file)
@@ -19,6 +19,7 @@
 #include <CDF_StoreList.hxx>
 #include <CDM_Document.hxx>
 #include <CDM_MetaData.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <CDM_ReferenceIterator.hxx>
 #include <PCDM_StorageDriver.hxx>
 #include <TCollection_ExtendedString.hxx>
index 9c12472df14bb5e230b039cf538bd6cd15075375..3370dc7cb7631e9c4d4d208abb716289f8fdf2fa 100644 (file)
 #include <TDF_DerivedAttribute.hxx>
 
 #include <NCollection_DataMap.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_CStringHasher.hxx>
 #include <TCollection_AsciiString.hxx>
 
+#include <mutex>
+
 namespace TDF_DerivedAttributeGlobals
 {
 
@@ -55,9 +56,9 @@ static NCollection_DataMap<Standard_CString, TCollection_AsciiString*, Standard_
 }
 
 //! To minimize simultaneous access to global "DERIVED" maps from parallel threads
-static Standard_Mutex& Mutex()
+static std::mutex& Mutex()
 {
-  static Standard_Mutex THE_DERIVED_MUTEX;
+  static std::mutex THE_DERIVED_MUTEX;
   return THE_DERIVED_MUTEX;
 }
 } // namespace TDF_DerivedAttributeGlobals
@@ -74,7 +75,7 @@ TDF_DerivedAttribute::NewDerived TDF_DerivedAttribute::Register(NewDerived theNe
   TDF_DerivedAttributeGlobals::CreatorData aData = {theNewAttributeFunction,
                                                     theNameSpace,
                                                     theTypeName};
-  Standard_Mutex::Sentry                   aSentry(TDF_DerivedAttributeGlobals::Mutex());
+  std::lock_guard<std::mutex>              aLock(TDF_DerivedAttributeGlobals::Mutex());
   TDF_DerivedAttributeGlobals::Creators().Append(aData);
   return theNewAttributeFunction;
 }
@@ -127,7 +128,7 @@ static void Initialize()
 
 Handle(TDF_Attribute) TDF_DerivedAttribute::Attribute(Standard_CString theType)
 {
-  Standard_Mutex::Sentry aSentry(TDF_DerivedAttributeGlobals::Mutex());
+  std::lock_guard<std::mutex> aLock(TDF_DerivedAttributeGlobals::Mutex());
   Initialize();
   if (const Handle(TDF_Attribute)* aResult =
         TDF_DerivedAttributeGlobals::Attributes().Seek(theType))
@@ -143,7 +144,7 @@ Handle(TDF_Attribute) TDF_DerivedAttribute::Attribute(Standard_CString theType)
 
 const TCollection_AsciiString& TDF_DerivedAttribute::TypeName(Standard_CString theType)
 {
-  Standard_Mutex::Sentry aSentry(TDF_DerivedAttributeGlobals::Mutex());
+  std::lock_guard<std::mutex> aLock(TDF_DerivedAttributeGlobals::Mutex());
   Initialize();
   if (TCollection_AsciiString* const* aResult = TDF_DerivedAttributeGlobals::Types().Seek(theType))
   {
@@ -157,7 +158,7 @@ const TCollection_AsciiString& TDF_DerivedAttribute::TypeName(Standard_CString t
 
 void TDF_DerivedAttribute::Attributes(NCollection_List<Handle(TDF_Attribute)>& theList)
 {
-  Standard_Mutex::Sentry aSentry(TDF_DerivedAttributeGlobals::Mutex());
+  std::lock_guard<std::mutex> aLock(TDF_DerivedAttributeGlobals::Mutex());
   Initialize();
   NCollection_DataMap<Standard_CString, Handle(TDF_Attribute), Standard_CStringHasher>::Iterator
     anAttrIter;
index f3b834023888ec330dfa3e0a55cc6fc370b48424..ac847436daa74672eeba4891d4532ae1a8563edb 100644 (file)
@@ -17,6 +17,7 @@
 #include <DE_Provider.hxx>
 #include <DE_Wrapper.hxx>
 #include <Message.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <OSD_File.hxx>
 #include <OSD_Path.hxx>
 #include <OSD_Protection.hxx>
index c70ae9f285b01387e80e989dd44454ef957e6fd3..45a93f1e4944cc6aa7f5dd8067f2914afd8efa96 100644 (file)
@@ -15,6 +15,8 @@
 #define _DE_PluginHolder_HeaderFile
 
 #include <DE_Wrapper.hxx>
+
+#include <mutex>
 #include <tuple>
 
 //! Base class to work with DE_Wrapper global registration of components.
@@ -28,14 +30,14 @@ class DE_PluginHolder
 public:
   DE_PluginHolder()
   {
-    Standard_Mutex::Sentry aLock(DE_Wrapper::GlobalLoadMutex());
+    std::lock_guard<std::mutex> aLock(DE_Wrapper::GlobalLoadMutex());
     myInternalConfiguration = new TheConfType;
     myInternalConfiguration->Register(DE_Wrapper::GlobalWrapper());
   }
 
   ~DE_PluginHolder()
   {
-    Standard_Mutex::Sentry aLock(DE_Wrapper::GlobalLoadMutex());
+    std::lock_guard<std::mutex> aLock(DE_Wrapper::GlobalLoadMutex());
     myInternalConfiguration->UnRegister(DE_Wrapper::GlobalWrapper());
   }
 
index 78997b5628b38d905fe5584e8ee635de64303b3d..5ec7122efaa095bb3cc8609cf5b4655e9676ef81 100644 (file)
@@ -91,9 +91,9 @@ void DE_Wrapper::SetGlobalWrapper(const Handle(DE_Wrapper)& theWrapper)
 
 //=================================================================================================
 
-Standard_Mutex& DE_Wrapper::GlobalLoadMutex()
+std::mutex& DE_Wrapper::GlobalLoadMutex()
 {
-  static Standard_Mutex THE_GLOBAL_LOAD_MUTEX;
+  static std::mutex THE_GLOBAL_LOAD_MUTEX;
   return THE_GLOBAL_LOAD_MUTEX;
 }
 
index a159adbe8d4fe23386b7e60d60c26a71c006c852..e29c3db8fff61e11a2cfd0cba130215ce1cff0ec 100644 (file)
 #include <Message_ProgressRange.hxx>
 #include <NCollection_DataMap.hxx>
 #include <NCollection_IndexedDataMap.hxx>
-#include <Standard_Mutex.hxx>
 #include <TColStd_ListOfAsciiString.hxx>
 
+#include <mutex>
+
 class TopoDS_Shape;
 class XSControl_WorkSession;
 class TDocStd_Document;
@@ -73,7 +74,7 @@ public:
   //! @param[in] theWrapper object to set as global configuration
   Standard_EXPORT static void SetGlobalWrapper(const Handle(DE_Wrapper)& theWrapper);
 
-  Standard_EXPORT static Standard_Mutex& GlobalLoadMutex();
+  Standard_EXPORT static std::mutex& GlobalLoadMutex();
 
 public:
   //! Reads a CAD file, according internal configuration
index 8e16905504fd86012a38e68d451a5c857d6443f4..7b7bafd42a330f56fbe4ff91ec73729357b02191 100644 (file)
@@ -67,7 +67,7 @@ public:
     }
     if (myThreadPool.HasThreads())
     {
-      Standard_Mutex::Sentry aLock(&myMutex);
+      std::lock_guard<std::mutex> aLock(myMutex);
       myProgress.Next();
     }
     else
@@ -84,7 +84,7 @@ protected:
 
 protected:
   NCollection_Vector<TopoDS_Face>* myFaceList;
-  mutable Standard_Mutex           myMutex;
+  mutable std::mutex               myMutex;
   mutable Message_ProgressScope    myProgress;
   const OSD_ThreadPool::Launcher&  myThreadPool;
 };
index 3ea71d9fcd3652f25c64851e21697fa27d095736..c35638a7ef0889b4f33835055341d7d0a51cd212 100644 (file)
@@ -19,6 +19,8 @@
 #include <STEPCAFControl_Controller.hxx>
 #include <XSAlgo.hxx>
 
+#include <mutex>
+
 IMPLEMENT_STANDARD_RTTIEXT(STEPCAFControl_Controller, STEPControl_Controller)
 
 //=================================================================================================
@@ -33,9 +35,9 @@ STEPCAFControl_Controller::STEPCAFControl_Controller()
 
 Standard_Boolean STEPCAFControl_Controller::Init()
 {
-  static Standard_Mutex theMutex;
+  static std::mutex           aMutex;
+  std::lock_guard<std::mutex> aLock(aMutex);
   {
-    Standard_Mutex::Sentry  aSentry(theMutex);
     static Standard_Boolean inic = Standard_False;
     if (inic)
       return Standard_True;
index 57827135c8b678f994b72b4955e843e54280979a..f4f00372f82fd5ee8f7ea2ae0f4e046fd65557e8 100644 (file)
 #include <XSAlgo_ShapeProcessor.hxx>
 #include <XSControl_WorkSession.hxx>
 
+#include <mutex>
+
 IMPLEMENT_STANDARD_RTTIEXT(STEPControl_Controller, XSControl_Controller)
 
 //  Pour NewModel et Write : definition de produit (temporaire ...)
 STEPControl_Controller::STEPControl_Controller()
     : XSControl_Controller("STEP", "step")
 {
-  static Standard_Boolean init = Standard_False;
-  static Standard_Mutex   aMutex;
-  aMutex.Lock();
+  static Standard_Boolean     init = Standard_False;
+  static std::mutex           aMutex;
+  std::lock_guard<std::mutex> aLock(aMutex);
   if (!init)
   {
     RWHeaderSection::Init();
@@ -338,7 +340,6 @@ STEPControl_Controller::STEPControl_Controller()
 
     init = Standard_True;
   }
-  aMutex.Unlock();
 
   Handle(STEPControl_ActorWrite) ActWrite = new STEPControl_ActorWrite;
   myAdaptorWrite                          = ActWrite;
index d0df52564d57cd4df2dea72c07b185391a7ae91b..387fe3a2957a8a68277153fd51fd8be330cacec4 100644 (file)
@@ -54,6 +54,7 @@
 #include <StepShape_ShapeDefinitionRepresentation.hxx>
 #include <StepShape_ShapeRepresentation.hxx>
 #include <StepShape_ShellBasedSurfaceModel.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TColStd_Array1OfAsciiString.hxx>
 #include <TColStd_Array1OfReal.hxx>
index ac875950b3281c1dda624bb3ac01767fac59f8c0..fbe8802cb6eaada651cb549d6f203f63bd713fe6 100644 (file)
 #include <IFSelect_SelectModelEntities.hxx>
 #include <IFSelect_SelectModelRoots.hxx>
 #include <IFSelect_SelectSignature.hxx>
-#include <Standard_Mutex.hxx>
 #include <StepAP214.hxx>
 #include <StepAP214_Protocol.hxx>
 #include <StepData_StepModel.hxx>
 #include <StepSelect_StepType.hxx>
 
+#include <mutex>
+
 Handle(Interface_Protocol) STEPEdit::Protocol()
 {
   /*
@@ -44,8 +45,8 @@ Handle(StepData_StepModel) STEPEdit::NewModel()
 
 Handle(IFSelect_Signature) STEPEdit::SignType()
 {
-  static Standard_Mutex              aMutex;
-  Standard_Mutex::Sentry             aSentry(aMutex);
+  static std::mutex                  aMutex;
+  std::lock_guard<std::mutex>        aLock(aMutex);
   static Handle(StepSelect_StepType) sty;
   if (!sty.IsNull())
     return sty;
index e25326ad3ecffc6310e46c29e8fcb8e1ca2fe1e7..d3f81660015fe665b0bd958c2b457a8c48998351 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <Interface_EntityIterator.hxx>
 #include <Interface_Graph.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_Transient.hxx>
 #include <Standard_Type.hxx>
 #include <StepGeom_CompositeCurve.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(STEPSelections_SelectGSCurves, IFSelect_SelectExplore)
 
-static Standard_Integer flag;
+namespace
+{
+thread_local Standard_Integer flag;
+} // namespace
 
 STEPSelections_SelectGSCurves::STEPSelections_SelectGSCurves()
     : IFSelect_SelectExplore(-1)
@@ -53,14 +55,11 @@ Standard_Boolean STEPSelections_SelectGSCurves::Explore(const Standard_Integer /
       for (subs.Start(); subs.More() && !isInGeomSet; subs.Next())
         if (subs.Value()->IsKind(STANDARD_TYPE(StepShape_GeometricSet)))
         {
-          static Standard_Mutex aMutex;
-          aMutex.Lock();
           if (flag)
           {
             explored.AddItem(subs.Value());
             flag = 0;
           }
-          aMutex.Unlock();
           isInGeomSet = Standard_True;
         }
       if (isInGeomSet)
index df54809a42b44d80d1611c24a8018261fccd4dea..a90bad1cb7fab13ed8b5e9b3da113cc39275bd81 100644 (file)
@@ -17,7 +17,6 @@
 #include <Interface_EntityIterator.hxx>
 #include <Interface_HGraph.hxx>
 #include <Interface_Macros.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_Transient.hxx>
 #include <Standard_Type.hxx>
 #include <STEPConstruct_Assembly.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(STEPSelections_SelectInstances, IFSelect_SelectExplore)
 
-static Handle(Interface_HGraph) myGraph;
-static Interface_EntityIterator myEntities;
+namespace
+{
+thread_local Handle(Interface_HGraph) myGraph;
+thread_local Interface_EntityIterator myEntities;
+} // namespace
 
 STEPSelections_SelectInstances::STEPSelections_SelectInstances()
     : IFSelect_SelectExplore(-1)
@@ -153,8 +155,6 @@ static void AddInstances(const Handle(Standard_Transient)& start,
 
 Interface_EntityIterator STEPSelections_SelectInstances::RootResult(const Interface_Graph& G) const
 {
-  static Standard_Mutex  aMutex;
-  Standard_Mutex::Sentry aSentry(aMutex);
   if (myGraph.IsNull() || (G.Model() != myGraph->Graph().Model()))
   {
     Interface_EntityIterator roots = G.RootEntities();
index 83a7ed9a8a7fd939e416b773832848961d3aabec..cd2f52d73b83d6fb155d7503c9ae320b204dc3f3 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
-#include <Standard_Mutex.hxx>
 
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
@@ -42,6 +41,7 @@
 #include "step.tab.hxx"
 
 #include <stdio.h>
+#include <mutex>
 
 #ifdef OCCT_DEBUG
   #define CHRONOMESURE
 
 namespace
 {
-static Standard_Mutex THE_GLOBAL_READ_MUTEX;
+static std::mutex& GetGlobalReadMutex()
+{
+  static std::mutex THE_GLOBAL_READ_MUTEX;
+  return THE_GLOBAL_READ_MUTEX;
 }
+} // namespace
 
 void StepFile_Interrupt(Standard_CString theErrorMessage, const Standard_Boolean theIsFail)
 {
@@ -119,8 +123,9 @@ static Standard_Integer StepFile_Read(const char*                            the
 
   sout << "      ...    STEP File   Read    ...\n";
 
-  Standard_Mutex::Sentry aLocker(THE_GLOBAL_READ_MUTEX);
-  Standard_Integer       nbhead, nbrec, nbpar;
+  std::lock_guard<std::mutex> aLock(GetGlobalReadMutex());
+
+  Standard_Integer nbhead, nbrec, nbpar;
   aFileDataModel.GetFileNbR(&nbhead, &nbrec, &nbpar); // renvoi par lex/yacc
   Handle(StepData_StepReaderData) undirec =
     // clang-format off
index 0f250168744233d2381c87e1754648d74abf8bb4..5ee44da6d867a29dc7e4f8e19ffcb9afaaedb26e 100644 (file)
@@ -14,7 +14,6 @@
 #include <Interface_InterfaceError.hxx>
 #include <Interface_InterfaceModel.hxx>
 #include <Interface_Macros.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_Transient.hxx>
 #include <Standard_Type.hxx>
 #include <StepData_Protocol.hxx>
index 04d6130c23edb0838b674e96042e005ce9f36440..62865d7e997204c376f9c292a3e32e2459a8ea4a 100644 (file)
@@ -38,6 +38,7 @@
 #include <ShapeAlgo_ToolContainer.hxx>
 #include <ShapeAnalysis_Curve.hxx>
 #include <ShapeAnalysis_Edge.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <ShapeBuild_Edge.hxx>
 #include <ShapeExtend_WireData.hxx>
 #include <ShapeFix_EdgeProjAux.hxx>
index 0f7be1897ea32af39dd6346be4e8f477db60e0e4..182015177b7dab9fd0627b150cf74eacda0c4099 100644 (file)
@@ -83,7 +83,7 @@ const Handle(VrmlData_Node)& VrmlData_Scene::AddNode(const Handle(VrmlData_Node)
   if (theN.IsNull() == Standard_False)
     if (theN->IsKind(STANDARD_TYPE(VrmlData_WorldInfo)) == Standard_False)
     {
-      myMutex.Lock();
+      std::lock_guard<std::mutex>  aLock(myMutex);
       const Handle(VrmlData_Node)& aNode =
         myAllNodes.Append((&theN->Scene() == this) ? theN : theN->Clone(NULL));
       // Name is checked for uniqueness. If not, letter 'D' is appended until
@@ -93,7 +93,6 @@ const Handle(VrmlData_Node)& VrmlData_Scene::AddNode(const Handle(VrmlData_Node)
           aNode->setName(aNode->Name(), "D");
       if (isTopLevel)
         myLstNodes.Append(aNode);
-      myMutex.Unlock();
       return aNode;
     }
   static Handle(VrmlData_Node) aNullNode;
@@ -108,8 +107,8 @@ const Handle(VrmlData_Node)& VrmlData_Scene::AddNode(const Handle(VrmlData_Node)
 
 Standard_OStream& operator<<(Standard_OStream& theOutput, const VrmlData_Scene& theScene)
 {
-  VrmlData_Scene& aScene = const_cast<VrmlData_Scene&>(theScene);
-  aScene.myMutex.Lock();
+  VrmlData_Scene&             aScene = const_cast<VrmlData_Scene&>(theScene);
+  std::lock_guard<std::mutex> aLock(aScene.myMutex);
   aScene.myCurrentIndent = 0;
   aScene.myLineError     = 0;
   aScene.myOutput        = 0L;
@@ -151,7 +150,6 @@ Standard_OStream& operator<<(Standard_OStream& theOutput, const VrmlData_Scene&
   aScene.myOutput = 0L;
   aScene.myNamedNodesOut.Clear();
   aScene.myUnnamedNodesOut.Clear();
-  aScene.myMutex.Unlock();
   return theOutput;
 }
 
@@ -326,8 +324,8 @@ VrmlData_ErrorStatus VrmlData_Scene::readHeader(VrmlData_InBuffer& theBuffer)
 
 VrmlData_Scene& VrmlData_Scene::operator<<(Standard_IStream& theInput)
 {
-  VrmlData_InBuffer aBuffer(theInput);
-  myMutex.Lock();
+  VrmlData_InBuffer           aBuffer(theInput);
+  std::lock_guard<std::mutex> aLock(myMutex);
   // Read the VRML header
   myStatus                                     = readHeader(aBuffer);
   const Handle(VrmlData_UnknownNode) aNullNode = new VrmlData_UnknownNode(*this);
@@ -365,7 +363,7 @@ VrmlData_Scene& VrmlData_Scene::operator<<(Standard_IStream& theInput)
   }
   if (myStatus != VrmlData_StatusOK)
     myLineError = aBuffer.LineCount;
-  myMutex.Unlock();
+
   return *this;
 }
 
index 9f08cbb16701872a482e1a567367d5488214f846..c201e905634d31545fe203e02114c4346217c92c 100644 (file)
 #include <Standard_IStream.hxx>
 #include <TCollection_ExtendedString.hxx>
 #include <NCollection_IncAllocator.hxx>
-#include <Standard_Mutex.hxx>
 #include <VrmlData_DataMapOfShapeAppearance.hxx>
 
+#include <mutex>
+
 // resolve name collisions with X11 headers
 #ifdef Status
   #undef Status
@@ -344,7 +345,7 @@ private:
 
   // read from stream
   NCollection_List<TCollection_ExtendedString> myVrmlDir;
-  Standard_Mutex                               myMutex;
+  std::mutex                                   myMutex;
   Standard_Integer                             myLineError; ///! #0 if error
 
   // write to stream
index 3762d1d8a0552ed8bb519c0def7a8234956a7d82..2a8e7260b8df6b9cceb0c15c385543f5eaa717b5 100644 (file)
@@ -132,7 +132,7 @@ bool RWMesh_TriangulationReader::finalizeLoading(
   }
   if (myLoadingStatistic)
   {
-    Standard_Mutex::Sentry aLock(myMutex);
+    std::lock_guard<std::mutex> aLock(myMutex);
     myLoadingStatistic->ExpectedNodesNb += theSourceMesh->NbDeferredNodes();
     myLoadingStatistic->ExpectedTrianglesNb += theSourceMesh->NbDeferredTriangles();
     myLoadingStatistic->DegeneratedTrianglesNb += theSourceMesh->DegeneratedTriNb();
index 39da96095163465ba4fb6f380f2b3119cb64384e..e911557e6c221d6fc6e11aa3979ee1bfd400db05 100644 (file)
@@ -16,7 +16,8 @@
 
 #include <Poly_Triangulation.hxx>
 #include <RWMesh_CoordinateSystemConverter.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
 
 class OSD_FileSystem;
 class RWMesh_TriangulationSource;
@@ -306,7 +307,7 @@ protected:
   RWMesh_CoordinateSystemConverter myCoordSysConverter; //!< coordinate system converter
   // clang-format off
   TCollection_AsciiString          myFileName;             //!< file name to use during message printing
-  mutable Standard_Mutex           myMutex;                //!< internal mutex to collect nodes/triangles statistic
+  mutable std::mutex           myMutex;                //!< internal mutex to collect nodes/triangles statistic
   mutable LoadingStatistic*        myLoadingStatistic;     //!< statistic of loaded triangulation
   Standard_Boolean                 myIsDoublePrecision;    //!< flag to fill in triangulation using single or double precision
   Standard_Boolean                 myToSkipDegenerateTris; //!< flag to skip degenerate triangles during loading, FALSE by default
index e41695cd68f179e292596e08b47af6436e36ac7f..27323346b1f6527b9a2665afc86a8c96c5c93aee 100644 (file)
 #include <Interface_InterfaceModel.hxx>
 #include <Interface_ShareTool.hxx>
 #include <Standard_Transient.hxx>
-#include <Standard_Mutex.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <NCollection_Vector.hxx>
 
+namespace
+{
 static int              THE_Interface_Category_init = 0;
 static Standard_CString unspec                      = "unspecified";
 
-static Standard_Mutex            gMapTypesMutex;
 static volatile Standard_Boolean gMapTypesInit = Standard_False;
 
 static NCollection_Vector<TCollection_AsciiString>& theCats()
@@ -32,6 +32,14 @@ static NCollection_Vector<TCollection_AsciiString>& theCats()
   return aCat;
 }
 
+static std::mutex& GetMapTypesMutex()
+{
+  static std::mutex gMapTypesMutex;
+  return gMapTypesMutex;
+}
+
+} // namespace
+
 Standard_Integer Interface_Category::CatNum(const Handle(Standard_Transient)& theEnt,
                                             const Interface_ShareTool&        theShares)
 {
@@ -118,7 +126,7 @@ void Interface_Category::Init()
   // On first call, initialize static map
   if (!gMapTypesInit)
   {
-    gMapTypesMutex.Lock();
+    std::lock_guard<std::mutex> aLock(GetMapTypesMutex());
     if (!gMapTypesInit)
     {
       if (THE_Interface_Category_init)
@@ -139,6 +147,5 @@ void Interface_Category::Init()
 
       gMapTypesInit = Standard_True;
     }
-    gMapTypesMutex.Unlock();
   }
 }
index 914e52632d56498fc1d20c2bda6e452fc819fac3..a3963fd4d14f3b8ae93158fa5f5189bf25251f86 100644 (file)
@@ -22,6 +22,7 @@
 #include <ShapeExtend_MsgRegistrator.hxx>
 #include <ShapeFix_Shape.hxx>
 #include <ShapeProcess_ShapeContext.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <TopExp_Explorer.hxx>
 #include <Transfer_FinderProcess.hxx>
 #include <Transfer_TransientListBinder.hxx>
index 55ab5cd46cc6efa82bf71563e14bc5caf7001057..74587e773fcccb5d702f70f88481798bf514f4cc 100644 (file)
@@ -18,6 +18,7 @@
 #include <Message_Messenger.hxx>
 #include <Standard_Failure.hxx>
 #include <Standard_Transient.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <Standard_Type.hxx>
 #include <Transfer_ActorOfFinderProcess.hxx>
 #include <Transfer_SimpleBinderOfTransient.hxx>
index 28ca31c754d6d785d2cdd9b6236ce33f3c287b05..adf5a5e59979f5a02737ccf5cb206415e9528519 100644 (file)
 #include <XSControl_Vars.hxx>
 #include <XSControl_WorkSession.hxx>
 
+#include <mutex>
+
 IMPLEMENT_STANDARD_RTTIEXT(XSControl_WorkSession, IFSelect_WorkSession)
 
 namespace
 {
-static Standard_Mutex WS_GLOBAL_MUTEX; //!< Mutex to prevent data races during reading and writing.
+std::mutex& GetGlobalMutex()
+{
+  static std::mutex WS_GLOBAL_MUTEX;
+  return WS_GLOBAL_MUTEX;
 }
+} // namespace
 
 //=================================================================================================
 
@@ -72,7 +78,7 @@ void XSControl_WorkSession::ClearData(const Standard_Integer mode)
 
 Standard_Boolean XSControl_WorkSession::SelectNorm(const Standard_CString normname)
 {
-  const Standard_Mutex::Sentry aMutexLock(WS_GLOBAL_MUTEX);
+  const std::lock_guard<std::mutex> aLock(GetGlobalMutex());
   // Old norm and results
   myTransferReader->Clear(-1);
   //  ????  Strictly speaking, cleanup to do in XWS: remove the items
@@ -430,8 +436,8 @@ Standard_Integer XSControl_WorkSession::TransferReadRoots(const Message_Progress
 
 Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel()
 {
-  const Standard_Mutex::Sentry     aMutexLock(WS_GLOBAL_MUTEX);
-  Handle(Interface_InterfaceModel) newmod;
+  const std::lock_guard<std::mutex> aLock(GetGlobalMutex());
+  Handle(Interface_InterfaceModel)  newmod;
   if (myController.IsNull())
     return newmod;
   newmod = myController->NewModel();
@@ -453,8 +459,8 @@ IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape(
   const Standard_Boolean       compgraph,
   const Message_ProgressRange& theProgress)
 {
-  const Standard_Mutex::Sentry aMutexLock(WS_GLOBAL_MUTEX);
-  IFSelect_ReturnStatus        status;
+  const std::lock_guard<std::mutex> aLock(GetGlobalMutex());
+  IFSelect_ReturnStatus             status;
   if (myController.IsNull())
     return IFSelect_RetError;
   const Handle(Interface_InterfaceModel)& model = Model();
index 2c0968362151aa99bfa18dfde9f1fd155d7dccca..88a38a6e55fa2bb88f13d800e0ab8d9ba6aa776d 100644 (file)
@@ -41,6 +41,7 @@
 #include <TDataStd_Name.hxx>
 #include <TDataStd_UAttribute.hxx>
 #include <TFunction_Function.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <TFunction_Logbook.hxx>
 #include <TFunction_DriverTable.hxx>
 #include <TNaming_Selector.hxx>
index 88e4e9d63b2e80346ddb1d176432e42c4b824f43..af634023e3f4b2cce54d3d811ffc6a57342ecc6c 100644 (file)
@@ -19,6 +19,7 @@
 #include <Standard.hxx>
 
 #include <Message_ProgressIndicator.hxx>
+#include <Standard_ThreadId.hxx>
 #include <Draw_Interpretor.hxx>
 
 class Draw_ProgressIndicator;
index 176a4ad18c68edca9c53c5c13b04db2c00e03543..15098f9e8f78047d9a73b59a68e6fd5b73ac3514 100644 (file)
@@ -3707,7 +3707,6 @@ static Standard_Integer OCC29745(Draw_Interpretor& theDI,
   return 0;
 }
 
-#include <Standard_Mutex.hxx>
 #include <NCollection_Sequence.hxx>
 #include <BinLDrivers.hxx>
 #include <BinDrivers.hxx>
index f4f05288c8435cfb688d222d1100efe473461c40..a78370577884e626cc8075a333366db980bbb2a8 100644 (file)
@@ -66,7 +66,7 @@ void ViewerTest_ContinuousRedrawer::Start(const Handle(V3d_View)& theView,
   else
   {
     {
-      Standard_Mutex::Sentry aLock(myMutex);
+      std::lock_guard<std::mutex> aLock(myMutex);
       myToStop  = false;
       myToPause = false;
     }
@@ -84,7 +84,7 @@ void ViewerTest_ContinuousRedrawer::Stop(const Handle(V3d_View)& theView)
   }
 
   {
-    Standard_Mutex::Sentry aLock(myMutex);
+    std::lock_guard<std::mutex> aLock(myMutex);
     myToStop  = true;
     myToPause = false;
   }
@@ -100,7 +100,7 @@ void ViewerTest_ContinuousRedrawer::Pause()
 {
   if (!myToPause)
   {
-    Standard_Mutex::Sentry aLock(myMutex);
+    std::lock_guard<std::mutex> aLock(myMutex);
     myToPause = true;
   }
 }
@@ -118,7 +118,7 @@ void ViewerTest_ContinuousRedrawer::doThreadLoop()
   {
     bool toPause = false;
     {
-      Standard_Mutex::Sentry aLock(myMutex);
+      std::lock_guard<std::mutex> aLock(myMutex);
       if (myToStop)
       {
         return;
index cf2c2592431d96ee9e894a02eeefd74046176fd8..8987cf78e0a987dbcc29b24766742431edeaa71d 100644 (file)
 
 #include <OSD_Thread.hxx>
 #include <Standard_Condition.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_Type.hxx>
 
+#include <mutex>
+
 class V3d_View;
 
 //! Auxiliary tool performing continuous redraws of specified window.
@@ -70,7 +71,7 @@ private:
 private:
   Handle(V3d_View)   myView;      //!< view to invalidate
   OSD_Thread         myThread;    //!< working thread
-  Standard_Mutex     myMutex;     //!< mutex for accessing common variables
+  std::mutex         myMutex;     //!< mutex for accessing common variables
   Standard_Condition myWakeEvent; //!< event to wake up working thread
   Standard_Real      myTargetFps; //!< desired update framerate
   volatile bool      myToStop;    //!< flag to stop working thread
index 0c4d5e2dfde2b25a228c8c87a8238f9cd5b31453..4623a202d2778d5b71cb7670adcfb7424e1312bb 100644 (file)
@@ -47,6 +47,7 @@
 #include <TopoDS_Shape.hxx>
 #include <Transfer_IteratorOfProcessForTransient.hxx>
 #include <Transfer_TransientProcess.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <XSAlgo.hxx>
 #include <XSAlgo_ShapeProcessor.hxx>
 #include <XSControl_TransferReader.hxx>
index b2065b76273498282c8ffcf6a4bcb565f3dc5e8f..ddc436c2e2b68e26b4ba68ee748ddbfcd9be71db 100644 (file)
@@ -43,6 +43,7 @@
 #include <TopoDS_Shape.hxx>
 #include <V3d_View.hxx>
 #include <ViewerTest.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <XSControl_WorkSession.hxx>
 #include <XSDRAW.hxx>
 #include <XSDRAWSTL_DataSource.hxx>
index 2c8a909178bbcd9e6dfb1bd454376863e6318ebd..c9850242b136aeb011dcf4726ede7ff74473d779 100644 (file)
 // =======================================================================
 Standard_Integer BVH_BuildQueue::Size()
 {
-  Standard_Integer aSize;
-
-  myMutex.Lock();
-  {
-    aSize = myQueue.Size();
-  }
-  myMutex.Unlock();
-
-  return aSize;
+  std::lock_guard<std::mutex> aLock(myMutex);
+  return myQueue.Size();
 }
 
 // =======================================================================
@@ -38,11 +31,8 @@ Standard_Integer BVH_BuildQueue::Size()
 // =======================================================================
 void BVH_BuildQueue::Enqueue(const Standard_Integer& theWorkItem)
 {
-  myMutex.Lock();
-  {
-    myQueue.Append(theWorkItem);
-  }
-  myMutex.Unlock();
+  std::lock_guard<std::mutex> aLock(myMutex);
+  myQueue.Append(theWorkItem);
 }
 
 // =======================================================================
@@ -51,31 +41,29 @@ void BVH_BuildQueue::Enqueue(const Standard_Integer& theWorkItem)
 // =======================================================================
 Standard_Integer BVH_BuildQueue::Fetch(Standard_Boolean& wasBusy)
 {
+  std::lock_guard<std::mutex> aLock(myMutex);
+
   Standard_Integer aQuery = -1;
+  if (!myQueue.IsEmpty())
   {
-    Standard_Mutex::Sentry aSentry(myMutex);
-
-    if (!myQueue.IsEmpty())
-    {
-      aQuery = myQueue.First();
+    aQuery = myQueue.First();
 
-      myQueue.Remove(1); // remove item from queue
-    }
+    myQueue.Remove(1); // remove item from queue
+  }
 
-    if (aQuery != -1)
-    {
-      if (!wasBusy)
-      {
-        ++myNbThreads;
-      }
-    }
-    else if (wasBusy)
+  if (aQuery != -1)
+  {
+    if (!wasBusy)
     {
-      --myNbThreads;
+      ++myNbThreads;
     }
-
-    wasBusy = aQuery != -1;
   }
+  else if (wasBusy)
+  {
+    --myNbThreads;
+  }
+
+  wasBusy = aQuery != -1;
 
   return aQuery;
 }
index bc44b62958530f5f09f6f20bb2065f325905a400..b83762030b59c27ebf41be109b1365b2c35769f2 100644 (file)
 
 #include <BVH_Builder.hxx>
 
-#include <Standard_Mutex.hxx>
 #include <NCollection_Sequence.hxx>
 
+#include <mutex>
+
 //! Command-queue for parallel building of BVH nodes.
 class BVH_BuildQueue
 {
@@ -60,7 +61,7 @@ protected:
 
 protected:
   //! Manages access serialization of working threads.
-  Standard_Mutex myMutex;
+  std::mutex myMutex;
 
   //! Number of active build threads.
   Standard_Integer myNbThreads;
index 917cccd379cef02f80530d06873fa88b8e8a5182..dbd3cea4df5db727c216fa9ae9f08945b4792bed 100644 (file)
@@ -20,6 +20,8 @@
 #include <BVH_BuildThread.hxx>
 #include <NCollection_Vector.hxx>
 
+#include <mutex>
+
 //! Abstract BVH builder based on the concept of work queue.
 //! Queue based BVH builders support parallelization with a
 //! fixed number of threads (maximum efficiency is achieved
@@ -177,7 +179,7 @@ void BVH_QueueBuilder<T, N>::addChildren(
 
   // Add child nodes
   {
-    Standard_Mutex::Sentry aSentry(theBuildQueue.myMutex);
+    std::lock_guard<std::mutex> aLock(theBuildQueue.myMutex);
 
     for (Standard_Integer anIdx = 0; anIdx < 2; ++anIdx)
     {
index 7d81bd895ed40e7b20aa7b1d0e2f17982bb1fbb2..dc7f3f7dba938bbae29dd89db21986a0cd6e0449 100644 (file)
 #include <NCollection_DataMap.hxx>
 #include <OSD_Environment.hxx>
 #include <TCollection_AsciiString.hxx>
-#include <Standard_Mutex.hxx>
 #include <OSD_OpenFile.hxx>
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <mutex>
 
 typedef NCollection_DataMap<TCollection_AsciiString, TCollection_ExtendedString>
   Message_DataMapOfExtendedString;
@@ -35,9 +35,9 @@ static Message_DataMapOfExtendedString& msgsDataMap()
 }
 
 // mutex used to prevent concurrent access to message registry
-static Standard_Mutex& Message_MsgFile_Mutex()
+static std::mutex& Message_MsgFile_Mutex()
 {
-  static Standard_Mutex theMutex;
+  static std::mutex theMutex;
   return theMutex;
 }
 
@@ -371,7 +371,7 @@ Standard_Boolean Message_MsgFile::AddMsg(const TCollection_AsciiString&    theKe
 {
   Message_DataMapOfExtendedString& aDataMap = ::msgsDataMap();
 
-  Standard_Mutex::Sentry aSentry(Message_MsgFile_Mutex());
+  std::lock_guard<std::mutex> aLock(Message_MsgFile_Mutex());
   aDataMap.Bind(theKeyword, theMessage);
   return Standard_True;
 }
@@ -390,7 +390,7 @@ const TCollection_ExtendedString& Message_MsgFile::Msg(const Standard_CString th
 
 Standard_Boolean Message_MsgFile::HasMsg(const TCollection_AsciiString& theKeyword)
 {
-  Standard_Mutex::Sentry aSentry(Message_MsgFile_Mutex());
+  std::lock_guard<std::mutex> aLock(Message_MsgFile_Mutex());
   return ::msgsDataMap().IsBound(theKeyword);
 }
 
@@ -402,7 +402,7 @@ const TCollection_ExtendedString& Message_MsgFile::Msg(const TCollection_AsciiSt
 {
   // find message in the map
   Message_DataMapOfExtendedString& aDataMap = ::msgsDataMap();
-  Standard_Mutex::Sentry           aSentry(Message_MsgFile_Mutex());
+  std::lock_guard<std::mutex>      aLock(Message_MsgFile_Mutex());
 
   // if message is not found, generate error message and add it to the map to minimize overhead
   // on consequent calls with the same key
index 4e7b55ebe8986899b72c6a3fd93efddbb9086eba..1a5a7c42c8f6dd8a4f35c0d878fb52b4fc8fda45 100644 (file)
 #ifndef _Message_ProgressIndicator_HeaderFile
 #define _Message_ProgressIndicator_HeaderFile
 
-#include <Standard_Mutex.hxx>
 #include <Standard_Handle.hxx>
+#include <Standard_Transient.hxx>
+#include <Standard_Type.hxx>
+
+#include <mutex>
 
 DEFINE_STANDARD_HANDLE(Message_ProgressIndicator, Standard_Transient)
 
@@ -135,7 +138,7 @@ private:
 
 private:
   Standard_Real          myPosition;  //!< Total progress position ranged from 0 to 1
-  Standard_Mutex         myMutex;     //!< Protection of myPosition from concurrent increment
+  std::mutex             myMutex;     //!< Protection of myPosition from concurrent increment
   Message_ProgressScope* myRootScope; //!< The root progress scope
 
 private:
@@ -151,7 +154,7 @@ inline void Message_ProgressIndicator::Increment(const Standard_Real          th
                                                  const Message_ProgressScope& theScope)
 {
   // protect incrementation by mutex to avoid problems in multithreaded scenarios
-  Standard_Mutex::Sentry aSentry(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
 
   myPosition = Min(myPosition + theStep, 1.);
 
index fc09ed5514fd02efb1a2a5832cfb41e996390466..c8071fdc8ca7d9cb677669102cbd787b7c2146b0 100644 (file)
@@ -41,7 +41,7 @@ Message_Report::Message_Report()
 
 void Message_Report::AddAlert(Message_Gravity theGravity, const Handle(Message_Alert)& theAlert)
 {
-  Standard_Mutex::Sentry aSentry(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
 
   // alerts of the top level
   if (myAlertLevels.IsEmpty())
@@ -168,7 +168,7 @@ void Message_Report::UpdateActiveInMessenger(const Handle(Message_Messenger)& th
 
 void Message_Report::AddLevel(Message_Level* theLevel, const TCollection_AsciiString& theName)
 {
-  Standard_Mutex::Sentry aSentry(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
 
   myAlertLevels.Append(theLevel);
 
@@ -204,7 +204,7 @@ void Message_Report::AddLevel(Message_Level* theLevel, const TCollection_AsciiSt
 
 void Message_Report::RemoveLevel(Message_Level* theLevel)
 {
-  Standard_Mutex::Sentry aSentry(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
 
   for (int aLevelIndex = myAlertLevels.Size(); aLevelIndex >= 1; aLevelIndex--)
   {
@@ -228,7 +228,7 @@ void Message_Report::Clear()
     return;
   }
 
-  Standard_Mutex::Sentry aSentry(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
 
   compositeAlerts()->Clear();
   myAlertLevels.Clear();
@@ -243,7 +243,7 @@ void Message_Report::Clear(Message_Gravity theGravity)
     return;
   }
 
-  Standard_Mutex::Sentry aSentry(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
 
   compositeAlerts()->Clear(theGravity);
   myAlertLevels.Clear();
@@ -258,7 +258,7 @@ void Message_Report::Clear(const Handle(Standard_Type)& theType)
     return;
   }
 
-  Standard_Mutex::Sentry aSentry(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
 
   compositeAlerts()->Clear(theType);
   myAlertLevels.Clear();
index 983414a27030266d8390c2811893bbd6f5a3256a..88019f312d4c4031263678187db59d9582d9b42e 100644 (file)
@@ -21,7 +21,8 @@
 #include <Message_MetricType.hxx>
 #include <NCollection_IndexedMap.hxx>
 #include <NCollection_Sequence.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
 
 class Message_CompositeAlerts;
 class Message_Messenger;
@@ -175,7 +176,7 @@ protected:
                                     const Handle(Message_CompositeAlerts)& theCompositeAlert);
 
 protected:
-  Standard_Mutex myMutex;
+  std::mutex myMutex;
 
   Handle(Message_CompositeAlerts) myCompositAlerts; //!< container of alerts
 
index f89a815404ac92e30c13ebc10dff3ed333e3dd38..c77ffb4883140c7eddd049f7f3621721066548a2 100644 (file)
@@ -15,7 +15,6 @@
 
 #include <NCollection_HeapAllocator.hxx>
 #include <Standard_OutOfMemory.hxx>
-#include <Standard_Mutex.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(NCollection_HeapAllocator, NCollection_BaseAllocator)
 
@@ -47,15 +46,6 @@ void NCollection_HeapAllocator::Free(void* anAddress)
 
 const Handle(NCollection_HeapAllocator)& NCollection_HeapAllocator::GlobalHeapAllocator()
 {
-  static Handle(NCollection_HeapAllocator) pAllocator;
-  if (pAllocator.IsNull())
-  {
-    static Standard_Mutex  theMutex;
-    Standard_Mutex::Sentry aSentry(theMutex);
-    if (pAllocator.IsNull())
-    {
-      pAllocator = new NCollection_HeapAllocator;
-    }
-  }
+  static Handle(NCollection_HeapAllocator) pAllocator = new NCollection_HeapAllocator;
   return pAllocator;
 }
index 1e4dc3895006783719a1503b9342a142c919ce5e..a43bda2931659205d9711f475a59bc6c8588e5fc 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <NCollection_IncAllocator.hxx>
 
-#include <Standard_Mutex.hxx>
 #include <Standard_OutOfMemory.hxx>
 
 #include <cmath>
@@ -72,13 +71,12 @@ void NCollection_IncAllocator::SetThreadSafe(const bool theIsThreadSafe)
   {
     if (!myMutex)
     {
-      myMutex = new Standard_Mutex;
+      myMutex = opencascade::make_unique<std::mutex>();
     }
   }
   else
   {
-    delete myMutex;
-    myMutex = nullptr;
+    myMutex.reset();
   }
 }
 
@@ -87,14 +85,14 @@ void NCollection_IncAllocator::SetThreadSafe(const bool theIsThreadSafe)
 NCollection_IncAllocator::~NCollection_IncAllocator()
 {
   clean();
-  delete myMutex;
 }
 
 //=================================================================================================
 
 void* NCollection_IncAllocator::AllocateOptimal(const size_t theSize)
 {
-  Standard_Mutex::Sentry aLock(myMutex);
+  std::unique_lock<std::mutex> aLock =
+    myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
   // Allocating using general block
   IBlock* aBlock = nullptr;
   // Use allocated blocks
@@ -164,8 +162,9 @@ void* NCollection_IncAllocator::Allocate(const size_t theSize)
 
 void NCollection_IncAllocator::clean()
 {
-  Standard_Mutex::Sentry aLock(myMutex);
-  IBlock*                aHeapIter = myOrderedBlocks;
+  std::unique_lock<std::mutex> aLock =
+    myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
+  IBlock* aHeapIter = myOrderedBlocks;
   while (aHeapIter)
   {
     IBlock* aCur = aHeapIter;
@@ -221,8 +220,9 @@ void NCollection_IncAllocator::Reset(const Standard_Boolean theReleaseMemory)
     clean();
     return;
   }
-  Standard_Mutex::Sentry aLock(myMutex);
-  IBlock*                aHeapIter = myOrderedBlocks;
+  std::unique_lock<std::mutex> aLock =
+    myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
+  IBlock* aHeapIter = myOrderedBlocks;
   while (aHeapIter)
   {
     IBlock* aCur    = aHeapIter;
index 185f9da82f060caaa9950b0c6074710188e1c441..a3da51b966d7077fa681497a8b7c605843573e85 100644 (file)
 #include <NCollection_BaseAllocator.hxx>
 #include <NCollection_OccAllocator.hxx>
 #include <NCollection_Allocator.hxx>
+#include <Standard_MemoryUtils.hxx>
 
 #include <utility>
-
-class Standard_Mutex;
+#include <mutex>
 
 /**
  *  Class NCollection_IncAllocator - incremental memory  allocator. This class
@@ -132,12 +132,12 @@ public:
   static constexpr size_t THE_MINIMUM_BLOCK_SIZE = 1024 * 2;
 
 private:
-  unsigned int    myBlockSize;                //!< Block size to incremental allocations
-  unsigned int    myBlockCount     = 0;       //!< Count of created blocks
-  Standard_Mutex* myMutex          = nullptr; //!< Thread-safety mutex
-  IBlock*         myAllocationHeap = nullptr; //!< Sorted list for allocations
-  IBlock*         myUsedHeap       = nullptr; //!< Sorted list for store empty blocks
-  IBlock*         myOrderedBlocks  = nullptr; //!< Ordered list for store growing size blocks
+  unsigned int                myBlockSize;                //!< Block size to incremental allocations
+  unsigned int                myBlockCount     = 0;       //!< Count of created blocks
+  std::unique_ptr<std::mutex> myMutex          = nullptr; //!< Thread-safety mutex
+  IBlock*                     myAllocationHeap = nullptr; //!< Sorted list for allocations
+  IBlock*                     myUsedHeap       = nullptr; //!< Sorted list for store empty blocks
+  IBlock* myOrderedBlocks = nullptr; //!< Ordered list for store growing size blocks
 
 public:
   // Declaration of CASCADE RTTI
index 629f2d2f857d084060fe17e662830a07f0fb90f2..2f2bab62448aedff0a7ee2e1e3fdc7debe1e6629 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
+#include <OSD_Environment.hxx>
+
+#include <OSD_OSDError.hxx>
+#include <OSD_WhoAmI.hxx>
+#include <Standard_ConstructionError.hxx>
+#include <Standard_Failure.hxx>
+#include <Standard_NullObject.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <NCollection_UtfString.hxx>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mutex>
+
 #ifndef _WIN32
 
-  #include <OSD_Environment.hxx>
-  #include <OSD_OSDError.hxx>
-  #include <OSD_WhoAmI.hxx>
-  #include <Standard_ConstructionError.hxx>
-  #include <Standard_Failure.hxx>
-  #include <Standard_Mutex.hxx>
-  #include <Standard_NullObject.hxx>
-  #include <TCollection_AsciiString.hxx>
-  #include <NCollection_UtfString.hxx>
-
-  #include <errno.h>
-  #include <stdio.h>
-  #include <stdlib.h>
-  #include <string.h>
 static const OSD_WhoAmI Iam = OSD_WEnvironment;
 
 // ----------------------------------------------------------------------
@@ -120,8 +122,8 @@ void OSD_Environment::Build()
   static int    Ibuffer = 0; // Tout ca pour putenv,getenv
 
   // Use mutex to avoid concurrent access to the buffer
-  static Standard_Mutex  theMutex;
-  Standard_Mutex::Sentry aSentry(theMutex);
+  static std::mutex           aMutex;
+  std::lock_guard<std::mutex> aLock(aMutex);
 
   // check if such variable has already been created in the buffer
   int index = -1, len = myName.Length();
@@ -216,17 +218,13 @@ Standard_Integer OSD_Environment::Error() const
 
   #include <windows.h>
 
-  #include <OSD_Environment.hxx>
-
   #include <NCollection_DataMap.hxx>
-  #include <NCollection_UtfString.hxx>
-  #include <Standard_Mutex.hxx>
 
   #ifdef OCCT_UWP
 namespace
 {
 // emulate global map of environment variables
-static Standard_Mutex                                                        THE_ENV_LOCK;
+static std::mutex                                                            THE_ENV_LOCK;
 static NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> THE_ENV_MAP;
 } // namespace
   #else
@@ -262,7 +260,7 @@ TCollection_AsciiString OSD_Environment::Value()
 {
   myValue.Clear();
   #ifdef OCCT_UWP
-  Standard_Mutex::Sentry aLock(THE_ENV_LOCK);
+  std::lock_guard<std::mutex> aLock(THE_ENV_LOCK);
   THE_ENV_MAP.Find(myName, myValue);
   #else
 
@@ -318,7 +316,7 @@ TCollection_AsciiString OSD_Environment ::Name() const
 void OSD_Environment::Build()
 {
   #ifdef OCCT_UWP
-  Standard_Mutex::Sentry aLock(THE_ENV_LOCK);
+  std::lock_guard<std::mutex> aLock(THE_ENV_LOCK);
   THE_ENV_MAP.Bind(myName, myValue);
   #else
   NCollection_Utf8String aSetVariable =
@@ -330,7 +328,7 @@ void OSD_Environment::Build()
 void OSD_Environment::Remove()
 {
   #ifdef OCCT_UWP
-  Standard_Mutex::Sentry aLock(THE_ENV_LOCK);
+  std::lock_guard<std::mutex> aLock(THE_ENV_LOCK);
   THE_ENV_MAP.UnBind(myName);
   #else
   NCollection_Utf8String aSetVariable = NCollection_Utf8String(myName.ToCString()) + "=";
index 2d10d4bd31d4577451c26b54b9d59cd527c06c50..5fff7d7ce27c5b10e6997b0a3cd4dbce19efd1ff 100644 (file)
 #include <OSD_ThreadPool.hxx>
 
 #include <NCollection_Array1.hxx>
-#include <Standard_Mutex.hxx>
 #include <OSD_Thread.hxx>
 
+#include <mutex>
+
 namespace
 {
 //! Class implementing tools for parallel processing
@@ -55,7 +56,7 @@ public:
     //! Thread-safe method.
     inline OSD_Parallel::UniversalIterator It() const
     {
-      Standard_Mutex::Sentry aMutex(myMutex);
+      std::lock_guard<std::mutex> aMutex(myMutex);
       return (myIt != myEnd) ? myIt++ : myEnd;
     }
 
@@ -71,7 +72,7 @@ public:
     const OSD_Parallel::UniversalIterator& myEnd;   //!< Last element of range.
                                                     // clang-format off
       mutable OSD_Parallel::UniversalIterator   myIt;    //!< First non processed element of range.
-      mutable Standard_Mutex                 myMutex; //!< Access controller for the first non processed element.
+      mutable std::mutex                        myMutex; //!< Access controller for the first non processed element.
                                                     // clang-format on
   };
 
index 140b3197b4166d4a31a0472492438d1b05bab721..f0de6d0b6f0596d221350898052286a9b746c10a 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <OSD.hxx>
 #include <OSD_Parallel.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <TCollection_AsciiString.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(OSD_ThreadPool, Standard_Transient)
index d551138c70ca1cf60919ca90bef57d7446c431f4..949fa4668f9c8fa44f62fe33497b2f9bff9b2cff 100644 (file)
@@ -18,7 +18,6 @@
 #include <NCollection_Array1.hxx>
 #include <OSD_Thread.hxx>
 #include <Standard_Condition.hxx>
-#include <Standard_Mutex.hxx>
 
 #include <atomic>
 
index 642fd1e1d6924239414fc211e0d3bf7f6c0c41a8..85c4920d74fa513e2271ad3b1f1da2fc909d7217 100644 (file)
@@ -17,6 +17,9 @@
 #include <Standard_Overflow.hxx>
 #include <Standard_Assert.hxx>
 
+#include <mutex>
+#include <signal.h>
+
 #include <Standard_WarningDisableFunctionCast.hxx>
 
 static OSD_SignalMode   OSD_WasSetSignal           = OSD_SignalMode_AsIs;
@@ -76,7 +79,6 @@ void OSD::SetSignalStackTraceLength(Standard_Integer theLength)
   #include <OSD_Environment.hxx>
   #include <Standard_Underflow.hxx>
   #include <Standard_ProgramError.hxx>
-  #include <Standard_Mutex.hxx>
 
   #ifdef _MSC_VER
     #include <eh.h>
@@ -84,7 +86,6 @@ void OSD::SetSignalStackTraceLength(Standard_Integer theLength)
   #endif
 
   #include <process.h>
-  #include <signal.h>
   #include <float.h>
 
 static Standard_Boolean fCtrlBrk;
@@ -92,7 +93,7 @@ static Standard_Boolean fCtrlBrk;
 static Standard_Boolean fMsgBox;
 
 // used to forbid simultaneous execution of setting / executing handlers
-static Standard_Mutex THE_SIGNAL_MUTEX;
+static std::mutex THE_SIGNAL_MUTEX;
 
 static LONG __fastcall _osd_raise(DWORD theCode, const char* theMsg, const char* theStack);
 static BOOL WINAPI _osd_ctrl_break_handler(DWORD);
@@ -121,9 +122,9 @@ static LONG CallHandler(DWORD theExceptionCode, EXCEPTION_POINTERS* theExcPtr)
     ExceptionInformation0 = theExcPtr->ExceptionRecord->ExceptionInformation[0];
   }
 
-  // clang-format off
-  Standard_Mutex::Sentry aSentry (THE_SIGNAL_MUTEX); // lock the mutex to prevent simultaneous handling
-  // clang-format on
+  // lock the mutex to prevent simultaneous handling
+  std::lock_guard<std::mutex> aLock(THE_SIGNAL_MUTEX);
+
   static char aBuffer[2048];
 
   bool isFloatErr = false;
@@ -309,9 +310,9 @@ static LONG CallHandler(DWORD theExceptionCode, EXCEPTION_POINTERS* theExcPtr)
 //=======================================================================
 static void SIGWntHandler(int signum, int sub_code)
 {
-  // clang-format off
-  Standard_Mutex::Sentry aSentry (THE_SIGNAL_MUTEX); // lock the mutex to prevent simultaneous handling
-  // clang-format on
+  // lock the mutex to prevent simultaneous handling
+  std::lock_guard<std::mutex> aLock(THE_SIGNAL_MUTEX);
+
   switch (signum)
   {
     case SIGFPE:
@@ -379,9 +380,6 @@ static void SIGWntHandler(int signum, int sub_code)
 
 static void TranslateSE(unsigned int theCode, EXCEPTION_POINTERS* theExcPtr)
 {
-  // clang-format off
-  Standard_Mutex::Sentry aSentry (THE_SIGNAL_MUTEX); // lock the mutex to prevent simultaneous handling
-  // clang-format on
   CallHandler(theCode, theExcPtr);
 }
   #endif
@@ -440,9 +438,9 @@ void OSD::SetThreadLocalSignal(OSD_SignalMode theSignalMode, Standard_Boolean th
 
 void OSD::SetSignal(OSD_SignalMode theSignalMode, Standard_Boolean theFloatingSignal)
 {
-  // clang-format off
-  Standard_Mutex::Sentry aSentry (THE_SIGNAL_MUTEX); // lock the mutex to prevent simultaneous handling
-  // clang-format on
+  // lock the mutex to prevent simultaneous handling
+  std::lock_guard<std::mutex> aLock(THE_SIGNAL_MUTEX);
+
   OSD_WasSetSignal = theSignalMode;
 
   #if !defined(OCCT_UWP) || defined(NTDDI_WIN10_TH2)
@@ -759,7 +757,6 @@ ACT_SIGIO_HANDLER* ADR_ACT_SIGIO_HANDLER = NULL;
 
   #ifdef __GNUC__
     #include <stdlib.h>
-    #include <stdio.h>
   #else
     #ifdef SA_SIGINFO
       #include <sys/siginfo.h>
@@ -767,8 +764,6 @@ ACT_SIGIO_HANDLER* ADR_ACT_SIGIO_HANDLER = NULL;
   #endif
 typedef void (*SIG_PFV)(int);
 
-  #include <signal.h>
-
   #if !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__) && defined(__GLIBC__)
     #include <sys/signal.h>
   #endif
index 5ec6e4865a45b660f381881e50000b8538362f83..c5c8beed0ce0d14557e22917e6bad2da7de9199b 100644 (file)
 //============================================================================
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard.hxx>
 
+#include <mutex>
+#include <shared_mutex>
+
 #ifndef _WIN32
   #include <pthread.h>
 #else
 //==== The top of the Errors Stack ===========================================
 static Standard_ErrorHandler* Top = 0;
 
-//! A mutex to protect from concurrent access to Top.
-//! Mutex is defined as function to avoid issues caused by
-//! an undefined static variables initialization order across compilation units (@sa #0031681 bug).
-//! Note that we should NOT use Sentry while in this class, as Sentry
-//! would register mutex as callback in the current exception handler.
-static Standard_Mutex& GetMutex()
+//=================================================================================================
+
+namespace
 {
-  static Standard_Mutex theMutex;
-  return theMutex;
-}
+// Using std::shared_mutex to allow concurrent read access from multiple threads.
+// Most FindHandler calls (theUnlink=false) use shared_lock for concurrent searches.
+// Only write operations (constructor, Unlink, FindHandler with theUnlink=true) use unique_lock.
+//
+// TODO: Long-term optimization - use thread_local storage to eliminate locking entirely.
+//       Since each thread only accesses its own error handlers (filtered by thread ID),
+//       this global list could be replaced with thread_local Top pointers.
+//       This would eliminate all mutex overhead for thousands of try blocks in multi-threaded code.
+static std::shared_mutex THE_GLOBAL_MUTEX;
 
 static inline Standard_ThreadId GetThreadID()
 {
@@ -58,6 +63,7 @@ static inline Standard_ThreadId GetThreadID()
   return GetCurrentThreadId();
 #endif
 }
+} // namespace
 
 //============================================================================
 //====  Constructor : Create a ErrorHandler structure. And add it at the
@@ -71,10 +77,9 @@ Standard_ErrorHandler::Standard_ErrorHandler()
   myThread = GetThreadID();
   memset(&myLabel, 0, sizeof(myLabel));
 
-  GetMutex().Lock();
+  std::unique_lock<std::shared_mutex> aLock(THE_GLOBAL_MUTEX);
   myPrevious = Top;
   Top        = this;
-  GetMutex().Unlock();
 }
 
 //============================================================================
@@ -96,7 +101,7 @@ void Standard_ErrorHandler::Destroy()
 void Standard_ErrorHandler::Unlink()
 {
   // put a lock on the stack
-  GetMutex().Lock();
+  std::unique_lock<std::shared_mutex> aLock(THE_GLOBAL_MUTEX);
 
   Standard_ErrorHandler* aPrevious = 0;
   Standard_ErrorHandler* aCurrent  = Top;
@@ -110,7 +115,6 @@ void Standard_ErrorHandler::Unlink()
 
   if (aCurrent == 0)
   {
-    GetMutex().Unlock();
     return;
   }
 
@@ -124,7 +128,6 @@ void Standard_ErrorHandler::Unlink()
     aPrevious->myPrevious = aCurrent->myPrevious;
   }
   myPrevious = 0;
-  GetMutex().Unlock();
 
   // unlink and destroy all registered callbacks
   Standard_Address aPtr = aCurrent->myCallbackPtr;
@@ -223,32 +226,54 @@ void Standard_ErrorHandler::Error(const Handle(Standard_Failure)& theError)
 Standard_ErrorHandler* Standard_ErrorHandler::FindHandler(const Standard_HandlerStatus theStatus,
                                                           const Standard_Boolean       theUnlink)
 {
-  // lock the stack
-  GetMutex().Lock();
+  // Use shared lock for read-only access (most common case), exclusive lock only when modifying
+  if (!theUnlink)
+  {
+    // Read-only path - use shared lock to allow concurrent searches from multiple threads
+    std::shared_lock<std::shared_mutex> aLock(THE_GLOBAL_MUTEX);
 
-  // Find the current ErrorHandler according to thread
-  Standard_ErrorHandler* aPrevious = 0;
-  Standard_ErrorHandler* aCurrent  = Top;
-  Standard_ErrorHandler* anActive  = 0;
-  Standard_Boolean       aStop     = Standard_False;
-  Standard_ThreadId      aTreadId  = GetThreadID();
+    // Find the current ErrorHandler according to thread
+    Standard_ErrorHandler* aCurrent = Top;
+    Standard_ThreadId      aTreadId = GetThreadID();
 
-  // searching an exception with correct ID number
-  // which is not processed for the moment
-  while (!aStop)
-  {
-    while (aCurrent != NULL && aTreadId != aCurrent->myThread)
+    // searching an exception with correct ID number
+    while (aCurrent != NULL)
     {
-      aPrevious = aCurrent;
-      aCurrent  = aCurrent->myPrevious;
+      if (aTreadId == aCurrent->myThread && theStatus == aCurrent->myStatus)
+      {
+        // found one
+        return aCurrent;
+      }
+      aCurrent = aCurrent->myPrevious;
     }
 
-    if (aCurrent != NULL)
+    return NULL;
+  }
+  else
+  {
+    // Modifying path - use exclusive lock
+    std::unique_lock<std::shared_mutex> aLock(THE_GLOBAL_MUTEX);
+
+    // Find the current ErrorHandler according to thread
+    Standard_ErrorHandler* aPrevious = 0;
+    Standard_ErrorHandler* aCurrent  = Top;
+    Standard_ErrorHandler* anActive  = 0;
+    Standard_Boolean       aStop     = Standard_False;
+    Standard_ThreadId      aTreadId  = GetThreadID();
+
+    // searching an exception with correct ID number
+    // which is not processed for the moment
+    while (!aStop)
     {
-      if (theStatus != aCurrent->myStatus)
+      while (aCurrent != NULL && aTreadId != aCurrent->myThread)
       {
+        aPrevious = aCurrent;
+        aCurrent  = aCurrent->myPrevious;
+      }
 
-        if (theUnlink)
+      if (aCurrent != NULL)
+      {
+        if (theStatus != aCurrent->myStatus)
         {
           // unlink current
           if (aPrevious == 0)
@@ -260,27 +285,26 @@ Standard_ErrorHandler* Standard_ErrorHandler::FindHandler(const Standard_Handler
           {
             aPrevious->myPrevious = aCurrent->myPrevious;
           }
-        }
 
-        // shift
-        aCurrent = aCurrent->myPrevious;
+          // shift
+          aCurrent = aCurrent->myPrevious;
+        }
+        else
+        {
+          // found one
+          anActive = aCurrent;
+          aStop    = Standard_True;
+        }
       }
       else
       {
-        // found one
-        anActive = aCurrent;
-        aStop    = Standard_True;
+        // Current is NULL, means that no handles
+        aStop = Standard_True;
       }
     }
-    else
-    {
-      // Current is NULL, means that no handlesr
-      aStop = Standard_True;
-    }
-  }
-  GetMutex().Unlock();
 
-  return anActive;
+    return anActive;
+  }
 }
 
 #if defined(OCC_CONVERT_SIGNALS)
index 1eec7475331e0c5711f94d8a8e894a18d30c93f3..f43109bf6463e9de97d506092e063e1a1d3cf24b 100644 (file)
@@ -26,6 +26,8 @@
 #include <Standard_ThreadId.hxx>
 #include <Standard_Type.hxx>
 
+#include <mutex>
+
 //! @file
 //! Support of handling of C signals as C++-style exceptions, and implementation
 //! of C++ exception handling on platforms that do not implement these natively.
index 1ed2bf5e4897884011cb784fa545aa5d3b57fed4..5ba1e5176b89a6f923990b07bd13ff3c74352977 100644 (file)
@@ -25,6 +25,7 @@
 #include <errno.h>
 
 #ifndef _WIN32
+  #include <unistd.h>
   #include <sys/mman.h> /* mmap() */
 #endif
 
@@ -310,9 +311,7 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize)
     // object life (such as myThreshold), and assume that calls to functions
     // of standard library are already protected by their implementation.
     // The unlock is called as soon as possible, for every treatment case.
-    // We also do not use Sentry, since in case if OCC signal or exception is
-    // caused by this block we will have deadlock anyway...
-    myMutex.Lock();
+    myMutex.lock();
 
     // if free block of the requested size is available, return it
     if (myFreeList[Index])
@@ -324,7 +323,7 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize)
       myFreeList[Index]     = *(Standard_Size**)aBlock;
 
       // unlock the mutex
-      myMutex.Unlock();
+      myMutex.unlock();
 
       // record size of the allocated block in the block header and
       // shift the pointer to the beginning of the user part of block
@@ -339,12 +338,12 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize)
     else if (RoundSize <= myCellSize)
     {
       // unlock the mutex for free lists
-      myMutex.Unlock();
+      myMutex.unlock();
 
       // and lock the specific mutex used to protect access to small blocks pools;
       // note that this is done by sentry class so as to ensure unlocking in case of
       // possible exception that may be thrown from AllocMemory()
-      Standard_Mutex::Sentry aSentry(myMutexPools);
+      std::lock_guard<std::mutex> aLock(myMutexPools);
 
       // check for availability of requested space in the current pool
       Standard_Size* aBlock = myNextAddr;
@@ -362,10 +361,10 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize)
           const Standard_Size aPIndex = INDEX_CELL(aRPSize);
           if (aPIndex > 0 && aPIndex <= myFreeListMax)
           {
-            myMutex.Lock();
+            myMutex.lock();
             *(Standard_Size**)myNextAddr = myFreeList[aPIndex];
             myFreeList[aPIndex]          = myNextAddr;
-            myMutex.Unlock();
+            myMutex.unlock();
           }
         }
 
@@ -391,7 +390,7 @@ Standard_Address Standard_MMgrOpt::Allocate(const Standard_Size aSize)
     else
     {
       // unlock the mutex immediately, as we do not need further to access any field
-      myMutex.Unlock();
+      myMutex.unlock();
 
       // we use operator ?: instead of if() since it is faster
       Standard_Size* aBlock =
@@ -461,16 +460,14 @@ void Standard_MMgrOpt::Free(Standard_Address theStorage)
     // Note that we do not lock fields that do not change during the
     // object life (such as myThreshold), and assume that calls to functions
     // of standard library are already protected by their implementation.
-    // We also do not use Sentry, since in case if OCC signal or exception is
-    // caused by this block we will have deadlock anyway...
-    myMutex.Lock();
-
-    // in the memory block header, record address of the next free block
-    *(Standard_Size**)aBlock = myFreeList[Index];
-    // add new block to be first in the list
-    myFreeList[Index] = aBlock;
+    {
+      std::lock_guard<std::mutex> aLock(myMutex);
 
-    myMutex.Unlock();
+      // in the memory block header, record address of the next free block
+      *(Standard_Size**)aBlock = myFreeList[Index];
+      // add new block to be first in the list
+      myFreeList[Index] = aBlock;
+    }
   }
   // otherwise, we have block of big size which shall be simply released
   else
@@ -485,7 +482,7 @@ void Standard_MMgrOpt::Free(Standard_Address theStorage)
 Standard_Integer Standard_MMgrOpt::Purge(Standard_Boolean)
 {
   // Lock access to critical data by mutex
-  Standard_Mutex::Sentry aSentry(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
 
   // TODO: implement support for isDeleted = True
 
@@ -507,7 +504,7 @@ Standard_Integer Standard_MMgrOpt::Purge(Standard_Boolean)
   }
 
   // Lock access to critical data by mutex
-  Standard_Mutex::Sentry aSentry1(myMutexPools);
+  std::lock_guard<std::mutex> aLock1(myMutexPools);
 
   // release memory pools containing no busy memory;
   // for that for each pool count the summary size of blocks
@@ -660,7 +657,7 @@ Standard_Integer Standard_MMgrOpt::Purge(Standard_Boolean)
 void Standard_MMgrOpt::FreePools()
 {
   // Lock access to critical data by mutex
-  Standard_Mutex::Sentry aSentry(myMutexPools);
+  std::lock_guard<std::mutex> aLock(myMutexPools);
 
   // last pool is remembered in myAllocList
   Standard_Size* aFree = myAllocList;
index acb6bfc534e9d5a3e68d395fb851224db5771e11..3385de51e62c1a94cee7f12c0de29e00ad1482bd 100644 (file)
@@ -17,7 +17,8 @@
 #define _Standard_MMgrOpt_HeaderFile
 
 #include <Standard_MMgrRoot.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
 
 /**
  * @brief Open CASCADE memory manager optimized for speed.
@@ -141,8 +142,8 @@ protected:
   // clang-format on
   Standard_Size myThreshold; //!< large block size
 
-  Standard_Mutex myMutex;      //!< Mutex to protect free lists data
-  Standard_Mutex myMutexPools; //!< Mutex to protect small block pools data
+  std::mutex myMutex;      //!< Mutex to protect free lists data
+  std::mutex myMutexPools; //!< Mutex to protect small block pools data
 };
 
 #endif
index 811c09e9bbc81768040c9ab4bcb9cc553470510b..e0b614452a6248d76d679744a77765302f241c9d 100644 (file)
@@ -15,7 +15,8 @@
 #include <Standard.hxx>
 
 #include <Message.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
 
 #include <Standard_WarningDisableFunctionCast.hxx>
 
@@ -71,9 +72,9 @@ public:
   }
 
   //! Return global mutex.
-  static Standard_Mutex& Mutex()
+  static std::mutex& Mutex()
   {
-    static Standard_Mutex THE_MUTEX_LOCK;
+    static std::mutex THE_MUTEX_LOCK;
     return THE_MUTEX_LOCK;
   }
 
@@ -234,8 +235,8 @@ Standard_Boolean Standard::StackTrace(char*     theBuffer,
   }
 
   // DbgHelp is not thread-safe library, hence global lock is used for serial access
-  Standard_Mutex::Sentry aSentry(Standard_DbgHelper::Mutex());
-  Standard_DbgHelper&    aDbgHelp = Standard_DbgHelper::GetDbgHelper();
+  std::lock_guard<std::mutex> aLock(Standard_DbgHelper::Mutex());
+  Standard_DbgHelper&         aDbgHelp = Standard_DbgHelper::GetDbgHelper();
   if (!aDbgHelp.IsLoaded())
   {
     strcat_s(theBuffer, theBufferSize, "\n==Backtrace==\n");
index 1fd4a6defe18387a7a662f694d87b39c138762e8..7aa0cc7d769f25027fa3dec5520eb76f67f86404 100644 (file)
@@ -17,7 +17,8 @@
 #include <NCollection_DataMap.hxx>
 #include <Standard_HashUtils.hxx>
 #include <Standard_Assert.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
 
 IMPLEMENT_STANDARD_RTTIEXT(Standard_Type, Standard_Transient)
 
@@ -115,8 +116,8 @@ Standard_Type* Standard_Type::Register(const std::type_info&        theInfo,
 {
   // Access to registry is protected by mutex; it should not happen often because
   // instances are cached by Standard_Type::Instance() (one per binary module)
-  static Standard_Mutex  aMutex;
-  Standard_Mutex::Sentry aSentry(aMutex);
+  static std::mutex           aMutex;
+  std::lock_guard<std::mutex> aLock(aMutex);
 
   // return existing descriptor if already in the registry
   registry_type& aRegistry = GetRegistry();
index 1f3e7e6844a3601463d5c80a284e6f421eeaaf51..3d77737a6413b6aaa4b7c5fd294a6fe9350879a0 100644 (file)
@@ -33,6 +33,7 @@
 #include <NCollection_Vector.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <TopoDS_Vertex.hxx>
 
 //=================================================================================================
index e6717298bb1f7605c5c92cc06b14bd3eb37df53c..70a61a628275c150fb000e0d5d30c31ea409467e 100644 (file)
@@ -31,6 +31,7 @@
 #include <BOPTools_Parallel.hxx>
 #include <BndLib_Add3dCurve.hxx>
 #include <BRep_Builder.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <gp_Pnt.hxx>
 #include <IntTools_CommonPrt.hxx>
index fa5d071c17b9e21c14fa6db9cfecfc9e87ba4cd6..a1d1e6b37a702fef9670c7162fb393aaf8afc717 100644 (file)
@@ -26,6 +26,7 @@
 #include <BOPDS_VectorOfInterfVF.hxx>
 #include <BOPTools_Parallel.hxx>
 #include <IntTools_Context.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <NCollection_Vector.hxx>
 #include <TColStd_MapOfInteger.hxx>
 #include <TopoDS_Face.hxx>
index 8dfa3e944eec8fbe99a935ec7173e36eadefd384..2f6cee3b551437d0ec746243c1685c129ee4254a 100644 (file)
@@ -32,6 +32,7 @@
 #include <BOPTools_Parallel.hxx>
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <GeomAPI_ProjectPointOnSurf.hxx>
 #include <gp_Pnt.hxx>
 #include <IntTools_CommonPrt.hxx>
index 7651e022eabcacd903a6334be87dd8ddc807344a..fe3e05a30af8f56f41c94bbb7bca4b65c36ba50e 100644 (file)
@@ -56,6 +56,7 @@
 #include <gp_Pnt.hxx>
 #include <IntSurf_ListOfPntOn2S.hxx>
 #include <IntSurf_PntOn2S.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <IntTools.hxx>
 #include <IntTools_Context.hxx>
 #include <IntTools_Curve.hxx>
index 06cba59e4772fee6a1f2f1b68655661ea981183f..2bb1fb2e2e1ad04a7b197d20e78c6385db0409ff 100644 (file)
@@ -45,6 +45,7 @@
 #include <Geom_Curve.hxx>
 #include <Geom_Plane.hxx>
 #include <Geom_RectangularTrimmedSurface.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <Geom_Surface.hxx>
 #include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <GeomAPI_ProjectPointOnSurf.hxx>
index 8449da0bc75299fa3bac98ce0ecb5ca5735e8de5..bf9ff4d9f69857724129a23b10a25e230917e125 100644 (file)
@@ -20,6 +20,7 @@
 #include <BOPAlgo_BuilderSolid.hxx>
 #include <BOPAlgo_MakerVolume.hxx>
 #include <BOPAlgo_Tools.hxx>
+#include <Standard_ErrorHandler.hxx>
 
 #include <BOPTools_AlgoTools.hxx>
 #include <BOPTools_Parallel.hxx>
index 0208d5c9932fb1fa85e6587e50815c9af24c8042..17a379941a82fa75e0021a81aa70d51436bff336 100644 (file)
 #include <OSD_Parallel.hxx>
 #include <OSD_ThreadPool.hxx>
 #include <NCollection_DataMap.hxx>
-#include <Standard_Mutex.hxx>
 #include <OSD_Thread.hxx>
 
+#include <mutex>
+
 //! Implementation of Functors/Starters
 class BOPTools_Parallel
 {
@@ -82,7 +83,7 @@ class BOPTools_Parallel
       opencascade::handle<TypeContext> aContext =
         new TypeContext(NCollection_BaseAllocator::CommonBaseAllocator());
 
-      Standard_Mutex::Sentry aLocker(myMutex);
+      std::lock_guard<std::mutex> aLock(myMutex);
       myContextMap.Bind(aThreadID, aContext);
       return myContextMap(aThreadID);
     }
@@ -104,7 +105,7 @@ class BOPTools_Parallel
   private:
     TypeSolverVector&                                                                mySolverVector;
     mutable NCollection_DataMap<Standard_ThreadId, opencascade::handle<TypeContext>> myContextMap;
-    mutable Standard_Mutex                                                           myMutex;
+    mutable std::mutex                                                               myMutex;
   };
 
   //! Functor storing array of algorithm contexts per thread in pool
index 09d731bb2d84356f71afda3029adc33245e0d27d..02d0480ee7e301c2b1250bab5ff66a0c6b80fb95 100644 (file)
@@ -17,6 +17,7 @@
 #define _IMeshTools_ModelAlgo_HeaderFile
 
 #include <Standard_Transient.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <Message_ProgressRange.hxx>
 
 class IMeshData_Model;
index a0363637ae63b3a2650ce20eb708ea425cbfc104..297446a071f27c46cc0030d1bb5fc0381227b172 100644 (file)
@@ -29,6 +29,7 @@
 #include <ShapeAnalysis_Curve.hxx>
 #include <ShapeAnalysis_Edge.hxx>
 #include <ShapeAnalysis_Surface.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <Geom_TrimmedCurve.hxx>
 #include <gp_Pln.hxx>
 #include <GeomAdaptor_Surface.hxx>
index 76b10617fe3b19775e46955682bb432ab5710425..bd56e12e7f6e86b0e55fa76e101dc0b072d2816a 100644 (file)
 #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>
 
+#include <mutex>
+
 #include <sys/stat.h>
 IMPLEMENT_STANDARD_RTTIEXT(ShapeProcess_Context, Standard_Transient)
 
-static Standard_Mutex THE_SHAPE_PROCESS_MUTEX;
+namespace
+{
+static std::mutex& GetShapeProcessMutex()
+{
+  static std::mutex THE_SHAPE_PROCESS_MUTEX;
+  return THE_SHAPE_PROCESS_MUTEX;
+}
+} // namespace
 
 //=================================================================================================
 
@@ -74,7 +82,7 @@ Handle(Resource_Manager) ShapeProcess_Context::LoadResourceManager(const Standar
 {
   // 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);
+  std::lock_guard<std::mutex> aLock(GetShapeProcessMutex());
   // Optimisation of loading resource file: file is load only once
   // and reloaded only if file date has changed
   static Handle(Resource_Manager) sRC;
index b9ff73bf0a1b84121673caded78357b019d1c12c..e034c2ccc77a7b33225cb7aa79f9d6d88b6a1e4b 100644 (file)
@@ -29,7 +29,6 @@
 #include <OSD_Parallel.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_NullObject.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
@@ -37,6 +36,8 @@
 #include <TopoDS_Shape.hxx>
 #include <TopTools_MapOfShape.hxx>
 
+#include <mutex>
+
 //! Functor for multi-threaded execution.
 class BRepCheck_ParallelAnalyzer
 {
@@ -166,7 +167,10 @@ public:
 
                 if (performwire)
                 {
-                  Standard_Mutex::Sentry aLock(aFaceEdgeRes->GetMutex());
+                  std::unique_lock<std::mutex> aLock =
+                    aFaceEdgeRes->GetMutex()
+                      ? std::unique_lock<std::mutex>(*aFaceEdgeRes->GetMutex())
+                      : std::unique_lock<std::mutex>();
                   if (aFaceEdgeRes->IsStatusOnShape(aShape))
                   {
                     BRepCheck_ListIteratorOfListOfStatus itl(aFaceEdgeRes->StatusOnShape(aShape));
@@ -211,7 +215,9 @@ public:
 
               if (orientofwires)
               {
-                Standard_Mutex::Sentry aLock(aFaceWireRes->GetMutex());
+                std::unique_lock<std::mutex> aLock =
+                  aFaceWireRes->GetMutex() ? std::unique_lock<std::mutex>(*aFaceWireRes->GetMutex())
+                                           : std::unique_lock<std::mutex>();
                 if (aFaceWireRes->IsStatusOnShape(aShape))
                 {
                   const BRepCheck_ListOfStatus& aStatusList = aFaceWireRes->StatusOnShape(aShape);
index c0cfac00320ff57573b16ccdfae5d5b008d00907..03bcaa011a20cc0632220e763a379e243ae9a0fc 100644 (file)
@@ -259,7 +259,8 @@ void BRepCheck_Edge::InContext(const TopoDS_Shape& S)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     if (myMap.IsBound(S))
     {
       return;
@@ -327,7 +328,7 @@ void BRepCheck_Edge::InContext(const TopoDS_Shape& S)
 
         BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
         constexpr Standard_Real                      eps           = Precision::PConfusion();
-        Standard_Boolean                             toRunParallel = !myMutex.IsNull();
+        const Standard_Boolean                       toRunParallel = myMutex != nullptr;
         while (itcr.More())
         {
           const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
@@ -571,7 +572,8 @@ Standard_Boolean BRepCheck_Edge::GeometricControls() const
 
 void BRepCheck_Edge::SetStatus(const BRepCheck_Status theStatus)
 {
-  Standard_Mutex::Sentry aLock(myMutex.get());
+  std::unique_lock<std::mutex> aLock =
+    myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
   BRepCheck::Add(*myMap(myShape), theStatus);
 }
 
index 3b2d62fd2a5102a6103f7f2f20fd416b57b33457..23f251018f5c4cb5234dccbe3db2bb1368e23bd0 100644 (file)
@@ -115,7 +115,8 @@ void BRepCheck_Face::InContext(const TopoDS_Shape& S)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     if (myMap.IsBound(S))
     {
       return;
@@ -163,7 +164,8 @@ BRepCheck_Status BRepCheck_Face::IntersectWires(const Standard_Boolean Update)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
 
@@ -292,7 +294,8 @@ BRepCheck_Status BRepCheck_Face::ClassifyWires(const Standard_Boolean Update)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
 
@@ -420,7 +423,8 @@ BRepCheck_Status BRepCheck_Face::OrientationOfWires(const Standard_Boolean Updat
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
 
@@ -535,7 +539,8 @@ BRepCheck_Status BRepCheck_Face::OrientationOfWires(const Standard_Boolean Updat
 
 void BRepCheck_Face::SetUnorientable()
 {
-  Standard_Mutex::Sentry aLock(myMutex.get());
+  std::unique_lock<std::mutex> aLock =
+    myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
   BRepCheck::Add(*myMap(myShape), BRepCheck_UnorientableShape);
 }
 
@@ -543,7 +548,8 @@ void BRepCheck_Face::SetUnorientable()
 
 void BRepCheck_Face::SetStatus(const BRepCheck_Status theStatus)
 {
-  Standard_Mutex::Sentry aLock(myMutex.get());
+  std::unique_lock<std::mutex> aLock =
+    myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
   BRepCheck::Add(*myMap(myShape), theStatus);
 }
 
index d753758c7c66ddca48c63773694122ca45c7f381..c28db7b81c63ec4ed23adad1b9e262e143587e06 100644 (file)
@@ -46,7 +46,8 @@ void BRepCheck_Result::Init(const TopoDS_Shape& S)
 
 void BRepCheck_Result::SetFailStatus(const TopoDS_Shape& S)
 {
-  Standard_Mutex::Sentry          aLock(myMutex.get());
+  std::unique_lock<std::mutex> aLock =
+    myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
   Handle(BRepCheck_HListOfStatus) aList;
   if (!myMap.Find(S, aList))
   {
@@ -84,8 +85,8 @@ void BRepCheck_Result::NextShapeInContext()
 
 void BRepCheck_Result::SetParallel(Standard_Boolean theIsParallel)
 {
-  if (theIsParallel && myMutex.IsNull())
+  if (theIsParallel && !myMutex)
   {
-    myMutex.reset(new Standard_HMutex());
+    myMutex = opencascade::make_unique<std::mutex>();
   }
 }
index 022e0108eb8c42bcc96d2014c3377b2338af1430..4f9d71c9f00d85b485342d122f9ffb7f100bd1b8 100644 (file)
 
 #include <Standard.hxx>
 
-#include <Standard_Mutex.hxx>
 #include <Standard_Transient.hxx>
 #include <BRepCheck_DataMapOfShapeListOfStatus.hxx>
 #include <BRepCheck_ListOfStatus.hxx>
+#include <Standard_MemoryUtils.hxx>
+
+#include <mutex>
 
 DEFINE_STANDARD_HANDLE(BRepCheck_Result, Standard_Transient)
 
@@ -80,10 +82,10 @@ protected:
   Standard_Boolean                     myMin;
   Standard_Boolean                     myBlind;
   BRepCheck_DataMapOfShapeListOfStatus myMap;
-  mutable Handle(Standard_HMutex)      myMutex;
+  mutable std::unique_ptr<std::mutex>  myMutex;
 
 private:
-  Standard_HMutex* GetMutex() { return myMutex.get(); }
+  std::unique_ptr<std::mutex>& GetMutex() { return myMutex; }
 
 private:
   BRepCheck_DataMapIteratorOfDataMapOfShapeListOfStatus myIter;
index 1914de42b228a86f591d8cb546efd8b6df4b200b..c604ed531285be30bbc384936f52e2aa8c0ce6fe 100644 (file)
@@ -177,7 +177,8 @@ void BRepCheck_Shell::InContext(const TopoDS_Shape& S)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     if (myMap.IsBound(S))
     {
       return;
@@ -247,7 +248,8 @@ BRepCheck_Status BRepCheck_Shell::Closed(const Standard_Boolean Update)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
 
@@ -429,7 +431,8 @@ BRepCheck_Status BRepCheck_Shell::Orientation(const Standard_Boolean Update)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
   BRepCheck_ListOfStatus& aStatusList = *aHList;
@@ -826,7 +829,8 @@ BRepCheck_Status BRepCheck_Shell::Orientation(const Standard_Boolean Update)
 
 void BRepCheck_Shell::SetUnorientable()
 {
-  Standard_Mutex::Sentry aLock(myMutex.get());
+  std::unique_lock<std::mutex> aLock =
+    myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
   BRepCheck::Add(*myMap(myShape), BRepCheck_UnorientableShape);
 }
 
@@ -841,7 +845,8 @@ Standard_Boolean BRepCheck_Shell::IsUnorientable() const
 
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
   BRepCheck_ListOfStatus& aStatusList = *aHList;
index 4f9c5391d421ede59016e25b8201368b7115a4ba..59dfa086bd64af53e1b8925eaa60ccfd10d134c9 100644 (file)
@@ -64,7 +64,8 @@ void BRepCheck_Vertex::InContext(const TopoDS_Shape& S)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     if (myMap.IsBound(S))
     {
       return;
index 60a4ec229784b22a4552d232872e1d382c3d7c60..e3a4a895e39e8b0ed53fed6407877794c7d2490f 100644 (file)
@@ -187,7 +187,8 @@ void BRepCheck_Wire::InContext(const TopoDS_Shape& S)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     if (myMap.IsBound(S))
     {
       return;
@@ -273,7 +274,8 @@ BRepCheck_Status BRepCheck_Wire::Closed(const Standard_Boolean Update)
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
 
@@ -540,7 +542,8 @@ BRepCheck_Status BRepCheck_Wire::Closed2d(const TopoDS_Face& theFace, const Stan
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
   BRepCheck_ListOfStatus& aStatusList = *aHList;
@@ -717,7 +720,8 @@ BRepCheck_Status BRepCheck_Wire::Orientation(const TopoDS_Face& F, const Standar
   BRepCheck_Status                theOstat = Closed();
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
   BRepCheck_ListOfStatus& aStatusList = *aHList;
@@ -1057,7 +1061,8 @@ BRepCheck_Status BRepCheck_Wire::SelfIntersect(const TopoDS_Face&     F,
 {
   Handle(BRepCheck_HListOfStatus) aHList;
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::unique_lock<std::mutex> aLock =
+      myMutex ? std::unique_lock<std::mutex>(*myMutex) : std::unique_lock<std::mutex>();
     aHList = myMap(myShape);
   }
   BRepCheck_ListOfStatus& aStatusList = *aHList;
index 4e6b8188c975012b3cad3d807be96438ea1e7199..d9a678b0bd53be384733556541e22ea32513222c 100644 (file)
@@ -28,6 +28,7 @@
 #include <TopoDS_Vertex.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Face.hxx>
+#include <Standard_MemoryUtils.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 #include <Precision.hxx>
 #include <BRepExtrema_UnCompatibleShape.hxx>
@@ -38,6 +39,8 @@
 #include <StdFail_NotDone.hxx>
 
 #include <algorithm>
+#include <atomic>
+#include <mutex>
 
 namespace
 {
@@ -696,7 +699,7 @@ struct TreatmentFunctor
         DistRef(0),
         InnerSol(NULL),
         IsDone(NULL),
-        Mutex(NULL)
+        Mutex()
   {
     for (Standard_Integer i = 0; i < theArrayOfArrays->Size(); ++i)
     {
@@ -717,7 +720,7 @@ struct TreatmentFunctor
         break;
       }
       aScope.Next();
-      if (*IsDone)
+      if (IsDone->load(std::memory_order_acquire))
       {
         break;
       }
@@ -727,10 +730,11 @@ struct TreatmentFunctor
       aClassifier.Perform(aPnt, aTolerance);
       if (aClassifier.State() == TopAbs_IN)
       {
-        Standard_Mutex::Sentry aLock(Mutex.get());
-        *InnerSol = Standard_True;
-        *DistRef  = 0.;
-        *IsDone   = Standard_True;
+        std::unique_lock<std::mutex> aLock =
+          Mutex ? std::unique_lock<std::mutex>(*Mutex) : std::unique_lock<std::mutex>();
+        InnerSol->store(true, std::memory_order_release);
+        *DistRef = 0.;
+        IsDone->store(true, std::memory_order_release);
         BRepExtrema_SolutionElem aSolElem(0, aPnt, BRepExtrema_IsVertex, aVertex);
         SolutionsShape1->Append(aSolElem);
         SolutionsShape2->Append(aSolElem);
@@ -746,9 +750,9 @@ struct TreatmentFunctor
   Message_ProgressScope                                 Scope;
   NCollection_Array1<Message_ProgressRange>             Ranges;
   Standard_Real*                                        DistRef;
-  volatile Standard_Boolean*                            InnerSol;
-  volatile Standard_Boolean*                            IsDone;
-  Handle(Standard_HMutex)                               Mutex;
+  std::atomic<bool>*                                    InnerSol;
+  std::atomic<bool>*                                    IsDone;
+  std::unique_ptr<std::mutex>                           Mutex;
 };
 
 //=================================================================================================
@@ -788,21 +792,29 @@ Standard_Boolean BRepExtrema_DistShapeShape::SolidTreatment(
     anArrayOfArray[aVectIndex][aShapeIndex] = theVertexMap(anI);
   }
 
+  // Create local atomic variables for thread-safe communication during parallel section
+  std::atomic<bool> anAtomicInnerSol(myInnerSol);
+  std::atomic<bool> anAtomicIsDone(myIsDone);
+
   Message_ProgressScope aScope(theRange, "Solid treatment", aNbTasks);
   TreatmentFunctor      aFunctor(&anArrayOfArray, aScope.Next());
   aFunctor.SolutionsShape1 = &mySolutionsShape1;
   aFunctor.SolutionsShape2 = &mySolutionsShape2;
   aFunctor.Shape           = theShape;
   aFunctor.DistRef         = &myDistRef;
-  aFunctor.InnerSol        = &myInnerSol;
-  aFunctor.IsDone          = &myIsDone;
-  if (myIsMultiThread)
+  aFunctor.InnerSol        = &anAtomicInnerSol;
+  aFunctor.IsDone          = &anAtomicIsDone;
+  if (myIsMultiThread && !aFunctor.Mutex)
   {
-    aFunctor.Mutex.reset(new Standard_HMutex());
+    aFunctor.Mutex = std::make_unique<std::mutex>();
   }
 
   OSD_Parallel::For(0, aNbTasks, aFunctor, !myIsMultiThread);
 
+  // Copy atomic results back to class members after parallel section completes
+  myInnerSol = anAtomicInnerSol.load(std::memory_order_acquire);
+  myIsDone   = anAtomicIsDone.load(std::memory_order_acquire);
+
   if (!aScope.More())
   {
     return Standard_False;
index 1f9638e82f32096938e479c2b9088d0a5243e80e..8ed9141000f61a3afea2920f80fa118250cd135b 100644 (file)
@@ -20,6 +20,7 @@
 #include <BRep_PointOnCurve.hxx>
 #include <BRep_PointOnCurveOnSurface.hxx>
 #include <BRep_PointOnSurface.hxx>
+#include <Standard_ErrorHandler.hxx>
 #include <TopoDS.hxx>
 
 //=================================================================================================
index 392a1d4d123bcfeadadd7ec8715ff8d151a8f15f..9a85e68c07ce6b796ac7115d5ebb67a21d8bdb52 100644 (file)
@@ -29,6 +29,7 @@
 #include <BinTools_Curve2dSet.hxx>
 #include <BinTools_SurfaceSet.hxx>
 #include <BinTools_OStream.hxx>
+#include <Standard_ErrorHandler.hxx>
 
 //=================================================================================================
 
index e01d90f0c52e1075d032a12a16296eef39d850b7..efb9e56f0c1091f25ab451fbcdd7678303b83a08 100644 (file)
@@ -49,8 +49,6 @@ set(OCCT_TopTools_FILES
   TopTools_MapIteratorOfMapOfShape.hxx
   TopTools_MapOfOrientedShape.hxx
   TopTools_MapOfShape.hxx
-  TopTools_MutexForShapeProvider.cxx
-  TopTools_MutexForShapeProvider.hxx
   TopTools_SequenceOfShape.hxx
   TopTools_ShapeMapHasher.hxx
   TopTools_ShapeSet.cxx
diff --git a/src/ModelingData/TKBRep/TopTools/TopTools_MutexForShapeProvider.cxx b/src/ModelingData/TKBRep/TopTools/TopTools_MutexForShapeProvider.cxx
deleted file mode 100644 (file)
index d095118..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-// Created on: 2012-06-27
-// Created by: Dmitry BOBYLEV
-// Copyright (c) 2012-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <TopTools_MutexForShapeProvider.hxx>
-
-#include <Standard_Mutex.hxx>
-#include <TopoDS_Iterator.hxx>
-
-// macro to compare two types of shapes
-#define SAMETYPE(x, y) ((x) == (y))
-#define LESSCOMPLEX(x, y) ((x) > (y))
-
-//=================================================================================================
-
-TopTools_MutexForShapeProvider::TopTools_MutexForShapeProvider() {}
-
-//=================================================================================================
-
-TopTools_MutexForShapeProvider::~TopTools_MutexForShapeProvider()
-{
-  RemoveAllMutexes();
-}
-
-//=================================================================================================
-
-void TopTools_MutexForShapeProvider::CreateMutexesForSubShapes(const TopoDS_Shape&    theShape,
-                                                               const TopAbs_ShapeEnum theType)
-{
-  if (LESSCOMPLEX(theShape.ShapeType(), theType))
-    return;
-
-  for (TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next())
-  {
-    const TopoDS_Shape& aShape = anIt.Value();
-    if (LESSCOMPLEX(theType, aShape.ShapeType()))
-    {
-      CreateMutexesForSubShapes(aShape, theType);
-    }
-    else if (SAMETYPE(theType, aShape.ShapeType()))
-    {
-      CreateMutexForShape(aShape);
-    }
-  }
-}
-
-//=================================================================================================
-
-void TopTools_MutexForShapeProvider::CreateMutexForShape(const TopoDS_Shape& theShape)
-{
-  if (!myMap.IsBound(theShape.TShape()))
-  {
-    Standard_Mutex* aMutex = new Standard_Mutex();
-    myMap.Bind(theShape.TShape(), aMutex);
-  }
-}
-
-//=================================================================================================
-
-Standard_Mutex* TopTools_MutexForShapeProvider::GetMutex(const TopoDS_Shape& theShape) const
-{
-  if (myMap.IsBound(theShape.TShape()))
-  {
-    Standard_Mutex* aMutex = myMap.Find(theShape.TShape());
-    return aMutex;
-  }
-  else
-  {
-    return NULL;
-  }
-}
-
-//=================================================================================================
-
-void TopTools_MutexForShapeProvider::RemoveAllMutexes()
-{
-  for (NCollection_DataMap<TopoDS_Shape, Standard_Mutex*>::Iterator anIter; anIter.More();
-       anIter.Next())
-  {
-    delete anIter.Value();
-  }
-  myMap.Clear();
-}
diff --git a/src/ModelingData/TKBRep/TopTools/TopTools_MutexForShapeProvider.hxx b/src/ModelingData/TKBRep/TopTools/TopTools_MutexForShapeProvider.hxx
deleted file mode 100644 (file)
index 63c9632..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-// Created on: 2012-06-27
-// Created by: Dmitry BOBYLEV
-// Copyright (c) 2012-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef _TopTools_MutexForShapeProvider_HeaderFile
-#define _TopTools_MutexForShapeProvider_HeaderFile
-
-#include <TopoDS_TShape.hxx>
-#include <NCollection_DataMap.hxx>
-#include <TopAbs_ShapeEnum.hxx>
-
-class Standard_Mutex;
-class TopoDS_Shape;
-
-//! Class TopTools_MutexForShapeProvider
-//!   This class is used to create and store mutexes associated with shapes.
-class TopTools_MutexForShapeProvider
-{
-public:
-  //! Constructor
-  Standard_EXPORT TopTools_MutexForShapeProvider();
-
-  //! Destructor
-  Standard_EXPORT ~TopTools_MutexForShapeProvider();
-
-  //! Creates and associates mutexes with each sub-shape of type theType in theShape.
-  Standard_EXPORT void CreateMutexesForSubShapes(const TopoDS_Shape&    theShape,
-                                                 const TopAbs_ShapeEnum theType);
-
-  //! Creates and associates mutex with theShape
-  Standard_EXPORT void CreateMutexForShape(const TopoDS_Shape& theShape);
-
-  //! Returns pointer to mutex associated with theShape.
-  //! In case when mutex not found returns NULL.
-  Standard_EXPORT Standard_Mutex* GetMutex(const TopoDS_Shape& theShape) const;
-
-  //! Removes all mutexes
-  Standard_EXPORT void RemoveAllMutexes();
-
-private:
-  //! This method should not be called (prohibited).
-  TopTools_MutexForShapeProvider(const TopTools_MutexForShapeProvider&);
-  //! This method should not be called (prohibited).
-  TopTools_MutexForShapeProvider& operator=(const TopTools_MutexForShapeProvider&);
-
-  NCollection_DataMap<Handle(TopoDS_TShape), Standard_Mutex*> myMap;
-};
-
-#endif
index b7ba56275c3525b6b7168868bd78881eae7f9147..ce348a53a34fd3478b126872f1cc7aeb3e46d768 100644 (file)
@@ -36,7 +36,6 @@
 #include <Standard_ConstructionError.hxx>
 #include <Standard_DimensionError.hxx>
 #include <Standard_DomainError.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_NoSuchObject.hxx>
 #include <Standard_NotImplemented.hxx>
 #include <Standard_OutOfRange.hxx>
index 48d7301a6d52c072a956e6644f86db4a489ad50c..3a9d4b3c7d7bbe5cf579be76de55dbe7a1c0d726 100644 (file)
@@ -28,7 +28,7 @@ Aspect_VKeySet::Aspect_VKeySet()
 
 void Aspect_VKeySet::Reset()
 {
-  Standard_Mutex::Sentry aLock(myLock);
+  std::lock_guard<std::shared_mutex> aLock(myLock);
   myModifiers = 0;
   for (NCollection_Array1<KeyState>::Iterator aKeyIter(myKeys); aKeyIter.More(); aKeyIter.Next())
   {
@@ -38,9 +38,8 @@ void Aspect_VKeySet::Reset()
 
 //=================================================================================================
 
-void Aspect_VKeySet::KeyDown(Aspect_VKey theKey, double theTime, double thePressure)
+void Aspect_VKeySet::KeyDown_Unlocked(Aspect_VKey theKey, double theTime, double thePressure)
 {
-  Standard_Mutex::Sentry aLock(myLock);
   if (myKeys[theKey].KStatus != KeyStatus_Pressed)
   {
     myKeys[theKey].KStatus  = KeyStatus_Pressed;
@@ -54,9 +53,16 @@ void Aspect_VKeySet::KeyDown(Aspect_VKey theKey, double theTime, double thePress
 
 //=================================================================================================
 
-void Aspect_VKeySet::KeyUp(Aspect_VKey theKey, double theTime)
+void Aspect_VKeySet::KeyDown(Aspect_VKey theKey, double theTime, double thePressure)
+{
+  std::lock_guard<std::shared_mutex> aLock(myLock);
+  KeyDown_Unlocked(theKey, theTime, thePressure);
+}
+
+//=================================================================================================
+
+void Aspect_VKeySet::KeyUp_Unlocked(Aspect_VKey theKey, double theTime)
 {
-  Standard_Mutex::Sentry aLock(myLock);
   if (myKeys[theKey].KStatus == KeyStatus_Pressed)
   {
     myKeys[theKey].KStatus = KeyStatus_Released;
@@ -72,32 +78,40 @@ void Aspect_VKeySet::KeyUp(Aspect_VKey theKey, double theTime)
 
 //=================================================================================================
 
+void Aspect_VKeySet::KeyUp(Aspect_VKey theKey, double theTime)
+{
+  std::lock_guard<std::shared_mutex> aLock(myLock);
+  KeyUp_Unlocked(theKey, theTime);
+}
+
+//=================================================================================================
+
 void Aspect_VKeySet::KeyFromAxis(Aspect_VKey theNegative,
                                  Aspect_VKey thePositive,
                                  double      theTime,
                                  double      thePressure)
 {
-  Standard_Mutex::Sentry aLock(myLock);
+  std::lock_guard<std::shared_mutex> aLock(myLock);
   if (thePressure != 0)
   {
     const Aspect_VKey aKeyDown = thePressure > 0 ? thePositive : theNegative;
     const Aspect_VKey aKeyUp   = thePressure < 0 ? thePositive : theNegative;
 
-    KeyDown(aKeyDown, theTime, Abs(thePressure));
+    KeyDown_Unlocked(aKeyDown, theTime, Abs(thePressure));
     if (myKeys[aKeyUp].KStatus == KeyStatus_Pressed)
     {
-      KeyUp(aKeyUp, theTime);
+      KeyUp_Unlocked(aKeyUp, theTime);
     }
   }
   else
   {
     if (myKeys[theNegative].KStatus == KeyStatus_Pressed)
     {
-      KeyUp(theNegative, theTime);
+      KeyUp_Unlocked(theNegative, theTime);
     }
     if (myKeys[thePositive].KStatus == KeyStatus_Pressed)
     {
-      KeyUp(thePositive, theTime);
+      KeyUp_Unlocked(thePositive, theTime);
     }
   }
 }
@@ -109,7 +123,7 @@ bool Aspect_VKeySet::HoldDuration(Aspect_VKey theKey,
                                   double&     theDuration,
                                   double&     thePressure)
 {
-  Standard_Mutex::Sentry aLock(myLock);
+  std::lock_guard<std::shared_mutex> aLock(myLock);
   switch (myKeys[theKey].KStatus)
   {
     case KeyStatus_Free: {
index eceeb1cae2070dc7c116f3b9e58a4f6e74de6c27..53939cfc39b4c3d58a91c81a2e77e6997062eddd 100644 (file)
 
 #include <NCollection_Array1.hxx>
 #include <OSD_Timer.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_Transient.hxx>
 
+#include <shared_mutex>
+
 //! Structure defining key state.
 class Aspect_VKeySet : public Standard_Transient
 {
@@ -32,42 +33,42 @@ public:
   //! Return active modifiers.
   Aspect_VKeyFlags Modifiers() const
   {
-    Standard_Mutex::Sentry aLock(myLock);
+    std::shared_lock<std::shared_mutex> aLock(myLock);
     return myModifiers;
   }
 
   //! Return timestamp of press event.
   double DownTime(Aspect_VKey theKey) const
   {
-    Standard_Mutex::Sentry aLock(myLock);
+    std::shared_lock<std::shared_mutex> aLock(myLock);
     return myKeys[theKey].TimeDown;
   }
 
   //! Return timestamp of release event.
   double TimeUp(Aspect_VKey theKey) const
   {
-    Standard_Mutex::Sentry aLock(myLock);
+    std::shared_lock<std::shared_mutex> aLock(myLock);
     return myKeys[theKey].TimeUp;
   }
 
   //! Return TRUE if key is in Free state.
   bool IsFreeKey(Aspect_VKey theKey) const
   {
-    Standard_Mutex::Sentry aLock(myLock);
+    std::shared_lock<std::shared_mutex> aLock(myLock);
     return myKeys[theKey].KStatus == KeyStatus_Free;
   }
 
   //! Return TRUE if key is in Pressed state.
   bool IsKeyDown(Aspect_VKey theKey) const
   {
-    Standard_Mutex::Sentry aLock(myLock);
+    std::shared_lock<std::shared_mutex> aLock(myLock);
     return myKeys[theKey].KStatus == KeyStatus_Pressed;
   }
 
   //! Return mutex for thread-safe updates.
   //! All operations in class implicitly locks this mutex,
   //! so this method could be used only for batch processing of keys.
-  Standard_Mutex& Mutex() { return myLock; }
+  std::shared_mutex& Mutex() { return myLock; }
 
 public:
   //! Reset the key state into unpressed state.
@@ -111,6 +112,13 @@ public:
                                     double&     theDuration,
                                     double&     thePressure);
 
+private:
+  //! Press key without locking (assumes lock is already held).
+  void KeyDown_Unlocked(Aspect_VKey theKey, double theTime, double thePressure);
+
+  //! Release key without locking (assumes lock is already held).
+  void KeyUp_Unlocked(Aspect_VKey theKey, double theTime);
+
 private:
   //! Key state.
   enum KeyStatus
@@ -147,7 +155,7 @@ private:
 
 private:
   NCollection_Array1<KeyState> myKeys;      //!< keys state
-  mutable Standard_Mutex       myLock;      //!< mutex for thread-safe updates
+  mutable std::shared_mutex    myLock;      //!< mutex for thread-safe updates
   Aspect_VKeyFlags             myModifiers; //!< active modifiers
 };
 
index 0f47156e5704d7e97c4963fff45f69cd5f1a5127..b01e965fe29ed14eb9851f3e264855edd45ab20a 100644 (file)
@@ -38,8 +38,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_MediaTexture, Graphic3d_Texture2D)
 
 //=================================================================================================
 
-Graphic3d_MediaTexture::Graphic3d_MediaTexture(const Handle(Standard_HMutex)& theMutex,
-                                               Standard_Integer               thePlane)
+Graphic3d_MediaTexture::Graphic3d_MediaTexture(std::mutex& theMutex, Standard_Integer thePlane)
     : Graphic3d_Texture2D("", Graphic3d_TypeOfTexture_2D),
       myMutex(theMutex),
       myPlane(thePlane)
@@ -54,7 +53,8 @@ Graphic3d_MediaTexture::Graphic3d_MediaTexture(const Handle(Standard_HMutex)& th
 
 Handle(Image_PixMap) Graphic3d_MediaTexture::GetImage(const Handle(Image_SupportedFormats)&)
 {
-  Standard_Mutex::Sentry aLock(myMutex.get());
+  std::lock_guard<std::mutex> aLock(myMutex);
+
   if (myFrame.IsNull() || myFrame->IsLocked() || myFrame->IsEmpty() || myFrame->SizeX() < 1
       || myFrame->SizeY() < 1)
   {
index 8584e3371723a9d57257ffc48afd6e59f0b7efdc..8b9ec55857e714e76b779abe34424e9ee4753dd1 100644 (file)
@@ -16,7 +16,8 @@
 #define _Graphic3d_MediaTexture_HeaderFile
 
 #include <Graphic3d_Texture2D.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
 
 class Media_Frame;
 
@@ -25,10 +26,6 @@ class Graphic3d_MediaTexture : public Graphic3d_Texture2D
 {
   DEFINE_STANDARD_RTTIEXT(Graphic3d_MediaTexture, Graphic3d_Texture2D)
 public:
-  //! Main constructor.
-  Standard_EXPORT Graphic3d_MediaTexture(const Handle(Standard_HMutex)& theMutex,
-                                         Standard_Integer               thePlane = -1);
-
   //! Image reader.
   Standard_EXPORT virtual Handle(Image_PixMap) GetImage(
     const Handle(Image_SupportedFormats)& theSupported) Standard_OVERRIDE;
@@ -42,11 +39,18 @@ public:
   //! Regenerate a new texture id
   void GenerateNewId() { generateId(); }
 
+  friend class Graphic3d_MediaTextureSet;
+
+private:
+  //! Main constructor.
+  //! Accessible only by Graphic3d_MediaTextureSet.
+  Standard_EXPORT Graphic3d_MediaTexture(std::mutex& theMutex, Standard_Integer thePlane = -1);
+
 protected:
-  mutable Handle(Standard_HMutex) myMutex;
-  Handle(Media_Frame)             myFrame;
-  Standard_Integer                myPlane;
-  mutable Handle(Image_PixMap)    myPixMapWrapper;
+  std::mutex&                  myMutex;
+  Handle(Media_Frame)          myFrame;
+  Standard_Integer             myPlane;
+  mutable Handle(Image_PixMap) myPixMapWrapper;
 };
 
 #endif // _Graphic3d_MediaTexture_HeaderFile
index 212bef5d19fc3d6515c957421bf6e01deced353a..f1af800ada8d018e53dc81feb8ed624fe06a98e8 100644 (file)
@@ -39,7 +39,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_MediaTextureSet, Graphic3d_TextureSet)
 
 Graphic3d_MediaTextureSet::Graphic3d_MediaTextureSet()
     : Graphic3d_TextureSet(4),
-      myMutex(new Standard_HMutex()),
+      myMutex(),
       myCallbackFunction(NULL),
       myCallbackUserPtr(NULL),
       myProgress(0.0),
@@ -156,7 +156,7 @@ void Graphic3d_MediaTextureSet::OpenInput(const TCollection_AsciiString& thePath
 Handle(Media_Frame) Graphic3d_MediaTextureSet::LockFrame()
 {
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::lock_guard<std::mutex> aLock(myMutex);
     if (!myToPresentFrame)
     {
       Handle(Media_Frame) aFrame = myFramePair[myFront == 0 ? 1 : 0];
@@ -179,7 +179,8 @@ Handle(Media_Frame) Graphic3d_MediaTextureSet::LockFrame()
 void Graphic3d_MediaTextureSet::ReleaseFrame(const Handle(Media_Frame)& theFrame)
 {
   {
-    Standard_Mutex::Sentry aLock(myMutex.get());
+    std::lock_guard<std::mutex> aLock(myMutex);
+
     theFrame->SetLocked(false);
     myToPresentFrame = true;
   }
@@ -201,7 +202,7 @@ Standard_Boolean Graphic3d_MediaTextureSet::SwapFrames()
   Standard_Boolean isPaused = Standard_False;
   myPlayerCtx->PlaybackState(isPaused, myProgress, myDuration);
 
-  Standard_Mutex::Sentry aLock(myMutex.get());
+  std::lock_guard<std::mutex> aLock(myMutex);
   if (!myToPresentFrame)
   {
     return Standard_False;
index 31bd32f03f56e1d520cf3a60cf2aec14d4b0871a..7693023c36b5b8548ca044e3e1a482ca8d83e7a7 100644 (file)
@@ -19,6 +19,8 @@
 #include <Graphic3d_MediaTexture.hxx>
 #include <Graphic3d_TextureSet.hxx>
 
+#include <mutex>
+
 class Graphic3d_ShaderProgram;
 class Media_PlayerContext;
 
@@ -93,7 +95,7 @@ protected:
   Handle(Media_Frame)             myFramePair[2];     //!< front/back frames pair
   Handle(Graphic3d_ShaderProgram) myShaderYUV;        //!< shader program for YUV  texture set
   Handle(Graphic3d_ShaderProgram) myShaderYUVJ;       //!< shader program for YUVJ texture set
-  Handle(Standard_HMutex)         myMutex;            //!< mutex for accessing frames
+  std::mutex                      myMutex;            //!< mutex for accessing frames
   TCollection_AsciiString         myInput;            //!< input media
   CallbackOnUpdate_t              myCallbackFunction; //!< callback function
   void*                           myCallbackUserPtr;  //!< callback data
index 99392798defc9023dbca904b2c943014e52f5e0f..1680284788ece44d02c1868842150e9b5157d82b 100644 (file)
@@ -225,7 +225,7 @@ void Media_PlayerContext::SetInput(const TCollection_AsciiString& theInputPath,
                                    Standard_Boolean               theToWait)
 {
   {
-    Standard_Mutex::Sentry aLock(myMutex);
+    std::lock_guard<std::mutex> aLock(myMutex);
     if (theToWait)
     {
       myNextEvent.Reset();
@@ -246,7 +246,7 @@ void Media_PlayerContext::PlaybackState(Standard_Boolean& theIsPaused,
                                         Standard_Real&    theProgress,
                                         Standard_Real&    theDuration)
 {
-  Standard_Mutex::Sentry aLock(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
   theIsPaused = !myTimer.IsStarted();
   theProgress = myTimer.ElapsedTime();
   theDuration = myDuration;
@@ -258,7 +258,7 @@ void Media_PlayerContext::PlayPause(Standard_Boolean& theIsPaused,
                                     Standard_Real&    theProgress,
                                     Standard_Real&    theDuration)
 {
-  Standard_Mutex::Sentry aLock(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
   theProgress = myTimer.ElapsedTime();
   theDuration = myDuration;
   if (myTimer.IsStarted())
@@ -277,16 +277,32 @@ void Media_PlayerContext::PlayPause(Standard_Boolean& theIsPaused,
 
 void Media_PlayerContext::Seek(Standard_Real thePosSec)
 {
-  Standard_Mutex::Sentry aLock(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
   mySeekTo = thePosSec;
   pushPlayEvent(Media_PlayerEvent_SEEK);
 }
 
 //=================================================================================================
 
+void Media_PlayerContext::Pause()
+{
+  std::lock_guard<std::mutex> aLock(myMutex);
+  pushPlayEvent(Media_PlayerEvent_PAUSE);
+}
+
+//=================================================================================================
+
+void Media_PlayerContext::Resume()
+{
+  std::lock_guard<std::mutex> aLock(myMutex);
+  pushPlayEvent(Media_PlayerEvent_RESUME);
+}
+
+//=================================================================================================
+
 void Media_PlayerContext::pushPlayEvent(Media_PlayerEvent thePlayEvent)
 {
-  Standard_Mutex::Sentry aLock(myMutex);
+  // NOTE: Caller must hold myMutex lock before calling this method
   myPlayEvent = thePlayEvent;
   myWakeEvent.Set();
 }
@@ -304,7 +320,7 @@ bool Media_PlayerContext::popPlayEvent(Media_PlayerEvent&                 thePla
     return false;
   }
 
-  Standard_Mutex::Sentry aLock(myMutex);
+  std::lock_guard<std::mutex> aLock(myMutex);
   thePlayEvent = myPlayEvent;
   if (thePlayEvent == Media_PlayerEvent_PAUSE)
   {
@@ -495,7 +511,7 @@ void Media_PlayerContext::doThreadLoop()
 
     TCollection_AsciiString anInput;
     {
-      Standard_Mutex::Sentry aLock(myMutex);
+      std::lock_guard<std::mutex> aLock(myMutex);
       std::swap(anInput, myInputPath);
       if (myPlayEvent == Media_PlayerEvent_NEXT)
       {
@@ -543,7 +559,7 @@ void Media_PlayerContext::doThreadLoop()
     Handle(Media_Packet) aPacket    = new Media_Packet();
     Media_PlayerEvent    aPlayEvent = Media_PlayerEvent_NONE;
     {
-      Standard_Mutex::Sentry aLock(myMutex);
+      std::lock_guard<std::mutex> aLock(myMutex);
       myTimer.Stop();
       myTimer.Start();
       myDuration = aFormatCtx->Duration();
index 9e5bf46c2757999f9077de672c8f7eb4198e1681..9019a4abd4b044772c29d1f2dbffae46e958abbb 100644 (file)
 #include <Media_Timer.hxx>
 #include <OSD_Thread.hxx>
 #include <Standard_Condition.hxx>
-#include <Standard_Mutex.hxx>
 #include <Standard_Transient.hxx>
 #include <Standard_Type.hxx>
 #include <TCollection_AsciiString.hxx>
 
+#include <mutex>
+
 class Media_BufferPool;
 class Media_CodecContext;
 class Media_FormatContext;
@@ -79,10 +80,10 @@ public:
   Standard_EXPORT void Seek(Standard_Real thePosSec);
 
   //! Pause playback.
-  void Pause() { pushPlayEvent(Media_PlayerEvent_PAUSE); }
+  Standard_EXPORT void Pause();
 
   //! Resume playback.
-  void Resume() { pushPlayEvent(Media_PlayerEvent_RESUME); }
+  Standard_EXPORT void Resume();
 
   //! Return TRUE if queue requires RGB pixel format or can handle also YUV pixel format; TRUE by
   //! default.
@@ -130,7 +131,7 @@ private:
 private:
   Media_IFrameQueue* myFrameQueue; //!< frame queue
   OSD_Thread         myThread;     //!< working thread
-  Standard_Mutex     myMutex;      //!< mutex for events
+  std::mutex         myMutex;      //!< mutex for events
                                    // clang-format off
   Standard_Condition          myWakeEvent;      //!< event to wake up working thread and proceed new playback event
   Standard_Condition          myNextEvent;      //!< event to check if working thread processed next file event (e.g. released file handles of previous input)
index 5cf03ae562ef736fbcec213b01c6d1bb1e375469..d4ab549065d8256a5c461bf8d4964296d415aae6 100644 (file)
@@ -2067,9 +2067,8 @@ void AIS_ViewController::handleViewOrientationKeys(const Handle(AIS_InteractiveC
     {Aspect_VKey_ViewRoll90CCW, (V3d_TypeOfOrientation)-1},
     {Aspect_VKey_ViewFitAll, (V3d_TypeOfOrientation)-1}};
   {
-    Standard_Mutex::Sentry aLock(myKeys.Mutex());
-    const size_t           aNbKeys     = sizeof(THE_VIEW_KEYS) / sizeof(*THE_VIEW_KEYS);
-    const double           anEventTime = EventTime();
+    const size_t aNbKeys     = sizeof(THE_VIEW_KEYS) / sizeof(*THE_VIEW_KEYS);
+    const double anEventTime = EventTime();
     for (size_t aKeyIter = 0; aKeyIter < aNbKeys; ++aKeyIter)
     {
       const ViewKeyAction& aKeyAction = THE_VIEW_KEYS[aKeyIter];
index f582c34b6f59946e64742bf4ace4702491518e8a..f84996b4d56a884cd9790138fee1459808a13e03 100644 (file)
@@ -31,7 +31,6 @@
 #include <OSD_Timer.hxx>
 #include <Precision.hxx>
 #include <Quantity_ColorRGBA.hxx>
-#include <Standard_Mutex.hxx>
 
 class AIS_Animation;
 class AIS_AnimationCamera;
index 942a2198ab249da6d16614acf083fe37082ed43c..06d91ab13ea9357fb35ee9678fcfefefc67b92c6 100644 (file)
@@ -21,6 +21,8 @@
 #include <Select3D_SensitiveSet.hxx>
 #include <Select3D_BVHIndexBuffer.hxx>
 #include <TColStd_HPackedMapOfInteger.hxx>
+#include <NCollection_Array1.hxx>
+#include <NCollection_Shared.hxx>
 
 //! Sensitive for triangulation or point set defined by Primitive Array.
 //! The primitives can be optionally combined into patches within BVH tree
index 1d12d7e395f1f4a01ef738374df3309aafc253fc..2bdd71ae8270d6afb544ea6b6d6d78efef879001 100644 (file)
 // commercial license or contractual agreement.
 
 #include <SelectMgr_BVHThreadPool.hxx>
+
 #include <Message.hxx>
 #include <OSD.hxx>
 #include <OSD_Parallel.hxx>
+#include <Standard_ErrorHandler.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_BVHThreadPool, Standard_Transient)
 
@@ -84,7 +86,7 @@ void SelectMgr_BVHThreadPool::AddEntity(const Handle(Select3D_SensitiveEntity)&
   }
 
   {
-    Standard_Mutex::Sentry aSentry(myBVHListMutex);
+    std::lock_guard<std::mutex> aLock(myBVHListMutex);
     myBVHToBuildList.Append(theEntity);
     myWakeEvent.Set();
     myIdleEvent.Reset();
@@ -115,19 +117,21 @@ void SelectMgr_BVHThreadPool::BVHThread::performThread()
       return;
     }
 
-    myPool->myBVHListMutex.Lock();
-    if (myPool->myBVHToBuildList.IsEmpty())
+    Handle(Select3D_SensitiveEntity) anEntity;
     {
-      myPool->myWakeEvent.Reset();
-      myPool->myIdleEvent.Set();
-      myPool->myBVHListMutex.Unlock();
-      continue;
+      std::lock_guard<std::mutex> aListLock(myPool->myBVHListMutex);
+      if (myPool->myBVHToBuildList.IsEmpty())
+      {
+        myPool->myWakeEvent.Reset();
+        myPool->myIdleEvent.Set();
+        continue;
+      }
+      anEntity = myPool->myBVHToBuildList.First();
+      myPool->myBVHToBuildList.RemoveFirst();
     }
-    Handle(Select3D_SensitiveEntity) anEntity = myPool->myBVHToBuildList.First();
-    myPool->myBVHToBuildList.RemoveFirst();
 
-    Standard_Mutex::Sentry anEntry(myMutex);
-    myPool->myBVHListMutex.Unlock();
+    // Lock thread mutex while building BVH
+    std::lock_guard<std::mutex> aThreadLock(myMutex);
 
     if (!anEntity.IsNull())
     {
index 2154155ebead19f3a18b689cc9a18e82d3069508..b733314fdd2670036069eab9932d74372da8581e 100644 (file)
 
 #include <Standard_Transient.hxx>
 #include <OSD_Thread.hxx>
-#include <Standard_Mutex.hxx>
 #include <Select3D_SensitiveEntity.hxx>
 #include <Standard_Condition.hxx>
 #include <Message_Messenger.hxx>
 
+#include <mutex>
+
 //! Class defining a thread pool for building BVH for the list of Select3D_SensitiveEntity within
 //! background thread(s).
 class SelectMgr_BVHThreadPool : public Standard_Transient
@@ -57,7 +58,7 @@ public:
     }
 
     //! Returns mutex used for BVH building
-    Standard_Mutex& BVHMutex() { return myMutex; }
+    std::mutex& BVHMutex() { return myMutex; }
 
     //! Assignment operator.
     BVHThread& operator=(const BVHThread& theCopy)
@@ -83,7 +84,7 @@ public:
 
   private:
     SelectMgr_BVHThreadPool* myPool;
-    Standard_Mutex           myMutex;
+    std::mutex               myMutex;
     bool                     myToCatchFpe;
   };
 
@@ -122,7 +123,7 @@ public:
       {
         for (Standard_Integer i = myPool->Threads().Lower(); i <= myPool->Threads().Upper(); ++i)
         {
-          myPool->Threads().ChangeValue(i).BVHMutex().Lock();
+          myPool->Threads().ChangeValue(i).BVHMutex().lock();
         }
       }
     }
@@ -134,7 +135,7 @@ public:
       {
         for (Standard_Integer i = myPool->Threads().Lower(); i <= myPool->Threads().Upper(); ++i)
         {
-          myPool->Threads().ChangeValue(i).BVHMutex().Unlock();
+          myPool->Threads().ChangeValue(i).BVHMutex().unlock();
         }
       }
     }
@@ -153,7 +154,7 @@ protected:
   NCollection_List<Handle(Select3D_SensitiveEntity)> myBVHToBuildList; //!< list of queued sensitive entities
   NCollection_Array1<BVHThread> myBVHThreads;                          //!< threads to build BVH
   Standard_Boolean myToStopBVHThread;                                  //!< flag to stop BVH threads
-  Standard_Mutex myBVHListMutex;                                       //!< mutex for interaction with myBVHToBuildList
+  std::mutex myBVHListMutex;                                           //!< mutex for interaction with myBVHToBuildList
   Standard_Condition myWakeEvent;                                      //!< raises when any sensitive is added to the BVH list
   Standard_Condition myIdleEvent;                                      //!< raises when BVH list become empty
   Standard_Boolean myIsStarted;                                        //!< indicates that threads are running
index bfecb2e7d8c7b79d5d31b659e5e22d422dab73df..3d7159c8d986bab789c5aaf239e62540c89cdf46 100644 (file)
@@ -256,8 +256,8 @@ bool StdPrs_BRepFont::FindAndInit(const TCollection_AsciiString& theFontName,
 
 TopoDS_Shape StdPrs_BRepFont::RenderGlyph(const Standard_Utf32Char& theChar)
 {
-  TopoDS_Shape           aShape;
-  Standard_Mutex::Sentry aSentry(myMutex);
+  TopoDS_Shape                aShape;
+  std::lock_guard<std::mutex> aLock(myMutex);
   renderGlyph(theChar, aShape);
   return aShape;
 }
index 8d9ed76a45b1a794154f8e543ab74b0f07f3fa33..54b5794571f2036a815243f4634aeebac8ea7203 100644 (file)
 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
 #include <NCollection_DataMap.hxx>
 #include <NCollection_String.hxx>
-#include <Standard_Mutex.hxx>
 #include <TColgp_Array1OfPnt2d.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopTools_SequenceOfShape.hxx>
 
+#include <mutex>
+
 DEFINE_STANDARD_HANDLE(StdPrs_BRepFont, Standard_Transient)
 
 //! This tool provides basic services for rendering of vectorized text glyphs as BRep shapes.
@@ -169,7 +170,7 @@ public:
   Standard_Real Scale() const { return myScaleUnits; }
 
   //! Returns mutex.
-  Standard_Mutex& Mutex() { return myMutex; }
+  std::mutex& Mutex() { return myMutex; }
 
 public:
   //! Find (using Font_FontMgr) and initialize the font from the given name.
@@ -206,7 +207,7 @@ private:
 protected:                                                        //! @name Protected fields
   Handle(Font_FTFont)                                   myFTFont; //!< wrapper over FreeType font
   NCollection_DataMap<Standard_Utf32Char, TopoDS_Shape> myCache;  //!< glyphs cache
-  Standard_Mutex                                        myMutex;  //!< lock for thread-safety
+  std::mutex                                            myMutex;  //!< lock for thread-safety
   Handle(Geom_Surface) mySurface;                                 //!< surface to place glyphs on to
   Standard_Real        myPrecision;                               //!< algorithm precision
   Standard_Real        myScaleUnits; //!< scale font rendering units into model units
index aa06521fbe9b8f2046e24ab0b49747b2105c141f..4613e47117b87ee5d167fd520793be650fe02e52 100644 (file)
@@ -23,11 +23,10 @@ TopoDS_Shape StdPrs_BRepTextBuilder::Perform(StdPrs_BRepFont&                  t
                                              const Handle(Font_TextFormatter)& theFormatter,
                                              const gp_Ax3&                     thePenLoc)
 {
-  gp_Trsf                aTrsf;
-  gp_XYZ                 aPen;
-  TopoDS_Shape           aGlyphShape;
-  TopoDS_Compound        aResult;
-  Standard_Mutex::Sentry aSentry(theFont.Mutex());
+  gp_Trsf         aTrsf;
+  gp_XYZ          aPen;
+  TopoDS_Shape    aGlyphShape;
+  TopoDS_Compound aResult;
 
   myBuilder.MakeCompound(aResult);
 
index deeca8f6d549267c971cc3b734c63725020aaa09..6e6c282c924e5300eeda4d631b253802ca95bc33 100644 (file)
@@ -37,7 +37,8 @@
 #include <TopoDS.hxx>
 #include <TopExp.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
 
 //! Functor for executing StdPrs_Isolines in parallel threads.
 class StdPrs_WFShape_IsoFunctor
@@ -63,7 +64,7 @@ public:
     const TopoDS_Face&         aFace = myFaces[theIndex];
     StdPrs_Isolines::Add(aFace, myDrawer, myShapeDeflection, aPolylinesU, aPolylinesV);
     {
-      Standard_Mutex::Sentry aLock(myMutex);
+      std::lock_guard<std::mutex> aLock(myMutex);
       myPolylinesU.Append(aPolylinesU);
       myPolylinesV.Append(aPolylinesV);
     }
@@ -77,7 +78,7 @@ private:
   Prs3d_NListOfSequenceOfPnt&     myPolylinesV;
   const std::vector<TopoDS_Face>& myFaces;
   const Handle(Prs3d_Drawer)&     myDrawer;
-  mutable Standard_Mutex          myMutex;
+  mutable std::mutex              myMutex;
   const Standard_Real             myShapeDeflection;
 };