- 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.
#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>
#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
{
}
//! 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
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;
}
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))
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))
{
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;
#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>
#define _DE_PluginHolder_HeaderFile
#include <DE_Wrapper.hxx>
+
+#include <mutex>
#include <tuple>
//! Base class to work with DE_Wrapper global registration of components.
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());
}
//=================================================================================================
-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;
}
#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;
//! @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
}
if (myThreadPool.HasThreads())
{
- Standard_Mutex::Sentry aLock(&myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
myProgress.Next();
}
else
protected:
NCollection_Vector<TopoDS_Face>* myFaceList;
- mutable Standard_Mutex myMutex;
+ mutable std::mutex myMutex;
mutable Message_ProgressScope myProgress;
const OSD_ThreadPool::Launcher& myThreadPool;
};
#include <STEPCAFControl_Controller.hxx>
#include <XSAlgo.hxx>
+#include <mutex>
+
IMPLEMENT_STANDARD_RTTIEXT(STEPCAFControl_Controller, STEPControl_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;
#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();
init = Standard_True;
}
- aMutex.Unlock();
Handle(STEPControl_ActorWrite) ActWrite = new STEPControl_ActorWrite;
myAdaptorWrite = ActWrite;
#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>
#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()
{
/*
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;
#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)
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)
#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)
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();
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
-#include <Standard_Mutex.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#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)
{
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
#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>
#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>
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
aNode->setName(aNode->Name(), "D");
if (isTopLevel)
myLstNodes.Append(aNode);
- myMutex.Unlock();
return aNode;
}
static Handle(VrmlData_Node) aNullNode;
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;
aScene.myOutput = 0L;
aScene.myNamedNodesOut.Clear();
aScene.myUnnamedNodesOut.Clear();
- aScene.myMutex.Unlock();
return theOutput;
}
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);
}
if (myStatus != VrmlData_StatusOK)
myLineError = aBuffer.LineCount;
- myMutex.Unlock();
+
return *this;
}
#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
// read from stream
NCollection_List<TCollection_ExtendedString> myVrmlDir;
- Standard_Mutex myMutex;
+ std::mutex myMutex;
Standard_Integer myLineError; ///! #0 if error
// write to stream
}
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();
#include <Poly_Triangulation.hxx>
#include <RWMesh_CoordinateSystemConverter.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
class OSD_FileSystem;
class RWMesh_TriangulationSource;
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
#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()
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)
{
// On first call, initialize static map
if (!gMapTypesInit)
{
- gMapTypesMutex.Lock();
+ std::lock_guard<std::mutex> aLock(GetMapTypesMutex());
if (!gMapTypesInit)
{
if (THE_Interface_Category_init)
gMapTypesInit = Standard_True;
}
- gMapTypesMutex.Unlock();
}
}
#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>
#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>
#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
//=================================================================================================
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
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();
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();
#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>
#include <Standard.hxx>
#include <Message_ProgressIndicator.hxx>
+#include <Standard_ThreadId.hxx>
#include <Draw_Interpretor.hxx>
class Draw_ProgressIndicator;
return 0;
}
-#include <Standard_Mutex.hxx>
#include <NCollection_Sequence.hxx>
#include <BinLDrivers.hxx>
#include <BinDrivers.hxx>
else
{
{
- Standard_Mutex::Sentry aLock(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
myToStop = false;
myToPause = false;
}
}
{
- Standard_Mutex::Sentry aLock(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
myToStop = true;
myToPause = false;
}
{
if (!myToPause)
{
- Standard_Mutex::Sentry aLock(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
myToPause = true;
}
}
{
bool toPause = false;
{
- Standard_Mutex::Sentry aLock(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
if (myToStop)
{
return;
#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.
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
#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>
#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>
// =======================================================================
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();
}
// =======================================================================
// =======================================================================
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);
}
// =======================================================================
// =======================================================================
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;
}
#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
{
protected:
//! Manages access serialization of working threads.
- Standard_Mutex myMutex;
+ std::mutex myMutex;
//! Number of active build threads.
Standard_Integer myNbThreads;
#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
// 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)
{
#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;
}
// 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;
}
{
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;
}
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);
}
{
// 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
#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)
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:
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.);
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())
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);
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--)
{
return;
}
- Standard_Mutex::Sentry aSentry(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
compositeAlerts()->Clear();
myAlertLevels.Clear();
return;
}
- Standard_Mutex::Sentry aSentry(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
compositeAlerts()->Clear(theGravity);
myAlertLevels.Clear();
return;
}
- Standard_Mutex::Sentry aSentry(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
compositeAlerts()->Clear(theType);
myAlertLevels.Clear();
#include <Message_MetricType.hxx>
#include <NCollection_IndexedMap.hxx>
#include <NCollection_Sequence.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
class Message_CompositeAlerts;
class Message_Messenger;
const Handle(Message_CompositeAlerts)& theCompositeAlert);
protected:
- Standard_Mutex myMutex;
+ std::mutex myMutex;
Handle(Message_CompositeAlerts) myCompositAlerts; //!< container of alerts
#include <NCollection_HeapAllocator.hxx>
#include <Standard_OutOfMemory.hxx>
-#include <Standard_Mutex.hxx>
IMPLEMENT_STANDARD_RTTIEXT(NCollection_HeapAllocator, NCollection_BaseAllocator)
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;
}
#include <NCollection_IncAllocator.hxx>
-#include <Standard_Mutex.hxx>
#include <Standard_OutOfMemory.hxx>
#include <cmath>
{
if (!myMutex)
{
- myMutex = new Standard_Mutex;
+ myMutex = opencascade::make_unique<std::mutex>();
}
}
else
{
- delete myMutex;
- myMutex = nullptr;
+ myMutex.reset();
}
}
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
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;
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;
#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
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
// 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;
// ----------------------------------------------------------------------
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();
#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
{
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
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 =
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()) + "=";
#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
//! 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;
}
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
};
#include <OSD.hxx>
#include <OSD_Parallel.hxx>
+#include <Standard_ErrorHandler.hxx>
#include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OSD_ThreadPool, Standard_Transient)
#include <NCollection_Array1.hxx>
#include <OSD_Thread.hxx>
#include <Standard_Condition.hxx>
-#include <Standard_Mutex.hxx>
#include <atomic>
#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;
#include <OSD_Environment.hxx>
#include <Standard_Underflow.hxx>
#include <Standard_ProgramError.hxx>
- #include <Standard_Mutex.hxx>
#ifdef _MSC_VER
#include <eh.h>
#endif
#include <process.h>
- #include <signal.h>
#include <float.h>
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);
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;
//=======================================================================
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:
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
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)
#ifdef __GNUC__
#include <stdlib.h>
- #include <stdio.h>
#else
#ifdef SA_SIGINFO
#include <sys/siginfo.h>
#endif
typedef void (*SIG_PFV)(int);
- #include <signal.h>
-
#if !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__) && defined(__GLIBC__)
#include <sys/signal.h>
#endif
//============================================================================
#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()
{
return GetCurrentThreadId();
#endif
}
+} // namespace
//============================================================================
//==== Constructor : Create a ErrorHandler structure. And add it at the
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();
}
//============================================================================
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;
if (aCurrent == 0)
{
- GetMutex().Unlock();
return;
}
aPrevious->myPrevious = aCurrent->myPrevious;
}
myPrevious = 0;
- GetMutex().Unlock();
// unlink and destroy all registered callbacks
Standard_Address aPtr = aCurrent->myCallbackPtr;
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)
{
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)
#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.
#include <errno.h>
#ifndef _WIN32
+ #include <unistd.h>
#include <sys/mman.h> /* mmap() */
#endif
// 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])
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
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;
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();
}
}
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 =
// 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
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
}
// 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
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;
#define _Standard_MMgrOpt_HeaderFile
#include <Standard_MMgrRoot.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
/**
* @brief Open CASCADE memory manager optimized for speed.
// 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
#include <Standard.hxx>
#include <Message.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
#include <Standard_WarningDisableFunctionCast.hxx>
}
//! 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;
}
}
// 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");
#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)
{
// 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();
#include <NCollection_Vector.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
+#include <Standard_ErrorHandler.hxx>
#include <TopoDS_Vertex.hxx>
//=================================================================================================
#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>
#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>
#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>
#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>
#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>
#include <BOPAlgo_BuilderSolid.hxx>
#include <BOPAlgo_MakerVolume.hxx>
#include <BOPAlgo_Tools.hxx>
+#include <Standard_ErrorHandler.hxx>
#include <BOPTools_AlgoTools.hxx>
#include <BOPTools_Parallel.hxx>
#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
{
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);
}
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
#define _IMeshTools_ModelAlgo_HeaderFile
#include <Standard_Transient.hxx>
+#include <Standard_ErrorHandler.hxx>
#include <Message_ProgressRange.hxx>
class IMeshData_Model;
#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>
#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
//=================================================================================================
{
// 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;
#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>
#include <TopoDS_Shape.hxx>
#include <TopTools_MapOfShape.hxx>
+#include <mutex>
+
//! Functor for multi-threaded execution.
class BRepCheck_ParallelAnalyzer
{
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));
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);
{
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;
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();
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);
}
{
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;
{
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);
}
{
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);
}
{
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);
}
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);
}
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);
}
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))
{
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>();
}
}
#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)
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;
{
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;
{
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);
}
{
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;
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);
}
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;
{
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;
{
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;
{
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);
}
{
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;
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;
{
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;
#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>
#include <StdFail_NotDone.hxx>
#include <algorithm>
+#include <atomic>
+#include <mutex>
namespace
{
DistRef(0),
InnerSol(NULL),
IsDone(NULL),
- Mutex(NULL)
+ Mutex()
{
for (Standard_Integer i = 0; i < theArrayOfArrays->Size(); ++i)
{
break;
}
aScope.Next();
- if (*IsDone)
+ if (IsDone->load(std::memory_order_acquire))
{
break;
}
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);
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;
};
//=================================================================================================
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;
#include <BRep_PointOnCurve.hxx>
#include <BRep_PointOnCurveOnSurface.hxx>
#include <BRep_PointOnSurface.hxx>
+#include <Standard_ErrorHandler.hxx>
#include <TopoDS.hxx>
//=================================================================================================
#include <BinTools_Curve2dSet.hxx>
#include <BinTools_SurfaceSet.hxx>
#include <BinTools_OStream.hxx>
+#include <Standard_ErrorHandler.hxx>
//=================================================================================================
TopTools_MapIteratorOfMapOfShape.hxx
TopTools_MapOfOrientedShape.hxx
TopTools_MapOfShape.hxx
- TopTools_MutexForShapeProvider.cxx
- TopTools_MutexForShapeProvider.hxx
TopTools_SequenceOfShape.hxx
TopTools_ShapeMapHasher.hxx
TopTools_ShapeSet.cxx
+++ /dev/null
-// 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();
-}
+++ /dev/null
-// 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
#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>
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())
{
//=================================================================================================
-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;
//=================================================================================================
-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;
//=================================================================================================
+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);
}
}
}
double& theDuration,
double& thePressure)
{
- Standard_Mutex::Sentry aLock(myLock);
+ std::lock_guard<std::shared_mutex> aLock(myLock);
switch (myKeys[theKey].KStatus)
{
case KeyStatus_Free: {
#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
{
//! 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.
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
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
};
//=================================================================================================
-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)
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)
{
#define _Graphic3d_MediaTexture_HeaderFile
#include <Graphic3d_Texture2D.hxx>
-#include <Standard_Mutex.hxx>
+
+#include <mutex>
class Media_Frame;
{
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;
//! 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
Graphic3d_MediaTextureSet::Graphic3d_MediaTextureSet()
: Graphic3d_TextureSet(4),
- myMutex(new Standard_HMutex()),
+ myMutex(),
myCallbackFunction(NULL),
myCallbackUserPtr(NULL),
myProgress(0.0),
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];
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;
}
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;
#include <Graphic3d_MediaTexture.hxx>
#include <Graphic3d_TextureSet.hxx>
+#include <mutex>
+
class Graphic3d_ShaderProgram;
class Media_PlayerContext;
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
Standard_Boolean theToWait)
{
{
- Standard_Mutex::Sentry aLock(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
if (theToWait)
{
myNextEvent.Reset();
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;
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())
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();
}
return false;
}
- Standard_Mutex::Sentry aLock(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
thePlayEvent = myPlayEvent;
if (thePlayEvent == Media_PlayerEvent_PAUSE)
{
TCollection_AsciiString anInput;
{
- Standard_Mutex::Sentry aLock(myMutex);
+ std::lock_guard<std::mutex> aLock(myMutex);
std::swap(anInput, myInputPath);
if (myPlayEvent == Media_PlayerEvent_NEXT)
{
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();
#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;
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.
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)
{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];
#include <OSD_Timer.hxx>
#include <Precision.hxx>
#include <Quantity_ColorRGBA.hxx>
-#include <Standard_Mutex.hxx>
class AIS_Animation;
class AIS_AnimationCamera;
#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
// 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)
}
{
- Standard_Mutex::Sentry aSentry(myBVHListMutex);
+ std::lock_guard<std::mutex> aLock(myBVHListMutex);
myBVHToBuildList.Append(theEntity);
myWakeEvent.Set();
myIdleEvent.Reset();
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())
{
#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
}
//! Returns mutex used for BVH building
- Standard_Mutex& BVHMutex() { return myMutex; }
+ std::mutex& BVHMutex() { return myMutex; }
//! Assignment operator.
BVHThread& operator=(const BVHThread& theCopy)
private:
SelectMgr_BVHThreadPool* myPool;
- Standard_Mutex myMutex;
+ std::mutex myMutex;
bool myToCatchFpe;
};
{
for (Standard_Integer i = myPool->Threads().Lower(); i <= myPool->Threads().Upper(); ++i)
{
- myPool->Threads().ChangeValue(i).BVHMutex().Lock();
+ myPool->Threads().ChangeValue(i).BVHMutex().lock();
}
}
}
{
for (Standard_Integer i = myPool->Threads().Lower(); i <= myPool->Threads().Upper(); ++i)
{
- myPool->Threads().ChangeValue(i).BVHMutex().Unlock();
+ myPool->Threads().ChangeValue(i).BVHMutex().unlock();
}
}
}
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
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;
}
#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.
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.
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
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);
#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
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);
}
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;
};