Coding - Replace Standard_Mutex with std::mutex and migrate to RAII locks (#766)

- 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.
This commit is contained in:
Pasukhin Dmitry
2025-11-03 16:44:08 +00:00
committed by GitHub
parent d98f74d893
commit 787bee375c
95 changed files with 562 additions and 568 deletions

View File

@@ -20,6 +20,7 @@
#include <BRep_PointOnCurve.hxx>
#include <BRep_PointOnCurveOnSurface.hxx>
#include <BRep_PointOnSurface.hxx>
#include <Standard_ErrorHandler.hxx>
#include <TopoDS.hxx>
//=================================================================================================

View File

@@ -29,6 +29,7 @@
#include <BinTools_Curve2dSet.hxx>
#include <BinTools_SurfaceSet.hxx>
#include <BinTools_OStream.hxx>
#include <Standard_ErrorHandler.hxx>
//=================================================================================================

View 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

View File

@@ -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();
}

View File

@@ -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