1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0022850: Not stable fix 22735

Class TopTools_MutexForShapeProvider has been created
Class contain methods:
TopTools_MutexForShapeProvider::CreateMutexesForSubShapes - Creates and associates mutexes with each sub-shape of type theType in theShape.
TopTools_MutexForShapeProvider::CreateMutexForShape - Creates and associates mutex with theShape
TopTools_MutexForShapeProvider::GetMutex - Returns pointer to mutex associated with theShape. In case when mutex not found returns NULL.

Added method RemoveAllMutexes to TopTools_MutexForShapeProvider
Assign operator in MutexProvider, constructor and operator and assign operator in Standard_Mutex now private
Replaced TopExp_Explorer with TopoDS_Iterator to avoid cyclic dependence
This commit is contained in:
dbv
2012-07-06 16:08:21 +04:00
parent 36f35343b8
commit d00cba631f
10 changed files with 246 additions and 10 deletions

View File

@@ -67,8 +67,9 @@ uses Boolean from Standard,
MapOfInteger from BRepMesh,
BaseAllocator from BRepMesh,
DataMapOfFaceAttribute from BRepMesh,
IndexedDataMapOfShapeListOfShape from TopTools
IndexedDataMapOfShapeListOfShape from TopTools,
MutexForShapeProvider from TopTools,
ShapeEnum from TopAbs
is
@@ -193,6 +194,17 @@ is
returns Boolean from Standard;
---Purpose:
-- Returns the multi-threading usage flag.
CreateMutexesForSubShapes(me : mutable;
theShape : Shape from TopoDS;
theType : ShapeEnum from TopAbs);
---Purpose:
-- Creates mutexes for each sub-shape of type theType in theShape.
-- Used to avoid data races.
RemoveAllMutexes(me: mutable);
---Purpose:
-- Removes all created mutexes
-- Output :
@@ -338,5 +350,6 @@ fields
myMapdefle : DataMapOfShapeReal from TopTools;
myNottriangulated : ListOfShape from TopTools;
myAllocator : BaseAllocator from BRepMesh;
myMutexProvider: MutexForShapeProvider from TopTools;
end FastDiscret;

View File

@@ -258,6 +258,7 @@ void BRepMesh_FastDiscret::Perform(const TopoDS_Shape& theShape)
if (myInParallel)
{
#ifdef HAVE_TBB
CreateMutexesForSubShapes(theShape, TopAbs_EDGE);
// mesh faces in parallel threads using TBB
tbb::parallel_for_each (aFaces.begin(), aFaces.end(), *this);
#else
@@ -265,6 +266,7 @@ void BRepMesh_FastDiscret::Perform(const TopoDS_Shape& theShape)
for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
Process (*it);
#endif
RemoveAllMutexes();
}
else
{
@@ -286,7 +288,7 @@ void BRepMesh_FastDiscret::Process(const TopoDS_Face& theFace) const
if ( GetFaceAttribute (theFace, fattribute) )
{
BRepMesh_FastDiscretFace aTool (GetAngle(), WithShare());
aTool.Add (theFace, fattribute, GetMapOfDefEdge());
aTool.Add (theFace, fattribute, GetMapOfDefEdge(), myMutexProvider);
}
//cout << "END face " << theFace.TShape().operator->() << endl << flush;
}
@@ -1687,3 +1689,22 @@ void BRepMesh_FastDiscret::RemoveFaceAttribute(const TopoDS_Face& theFace)
if(myMapattrib.IsBound(theFace))
myMapattrib.UnBind(theFace);
}
//=======================================================================
//function : CreateMutexesForSubShapes
//purpose :
//=======================================================================
void BRepMesh_FastDiscret::CreateMutexesForSubShapes(const TopoDS_Shape& theShape,
const TopAbs_ShapeEnum theType)
{
myMutexProvider.CreateMutexesForSubShapes(theShape, theType);
}
//=======================================================================
//function : RemoveAllMutexes
//purpose :
//=======================================================================
void BRepMesh_FastDiscret::RemoveAllMutexes()
{
myMutexProvider.RemoveAllMutexes();
}

View File

@@ -39,6 +39,7 @@ uses Boolean from Standard,
DataMapOfVertexInteger from BRepMesh,
DataMapOfIntegerListOfXY from BRepMesh,
DataMapOfShapeReal from TopTools,
MutexForShapeProvider from TopTools,
ListOfVertex from BRepMesh,
ClassifierPtr from BRepMesh,
Triangle from BRepMesh,
@@ -54,7 +55,6 @@ uses Boolean from Standard,
Triangulation from Poly,
Location from TopLoc
is
Create (theAngle : Real from Standard;
@@ -67,7 +67,8 @@ is
Add (me : mutable;
theFace : Face from TopoDS;
theAttrib : FaceAttribute from BRepMesh;
theMapDefle : DataMapOfShapeReal from TopTools)
theMapDefle : DataMapOfShapeReal from TopTools;
theMutexProvider : MutexForShapeProvider from TopTools)
is static;
@@ -116,7 +117,8 @@ is
AddInShape (me: mutable;
theFace : Face from TopoDS;
theDefFace: Real from Standard)
theDefFace: Real from Standard;
theMutexProvider: MutexForShapeProvider from TopTools)
is static private;

View File

@@ -108,7 +108,8 @@ BRepMesh_FastDiscretFace::BRepMesh_FastDiscretFace
void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace,
const Handle(BRepMesh_FaceAttribute)& theAttrib,
const TopTools_DataMapOfShapeReal& theMapDefle)
const TopTools_DataMapOfShapeReal& theMapDefle,
const TopTools_MutexForShapeProvider& theMutexProvider)
{
#ifndef DEB_MESH
try
@@ -324,7 +325,7 @@ void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace
}
myStructure->ReplaceNodes(aMoveNodes);
AddInShape(face, (aDef < 0.0)? theAttrib->GetDefFace() : aDef);
AddInShape(face, (aDef < 0.0)? theAttrib->GetDefFace() : aDef, theMutexProvider);
#ifndef DEB_MESH
}
catch(Standard_Failure)
@@ -1522,12 +1523,15 @@ Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurfac
return Sqrt(maxdef);
}
static Standard_Mutex DummyMutex;
//=======================================================================
//function : AddInShape
//purpose :
//=======================================================================
void BRepMesh_FastDiscretFace::AddInShape(const TopoDS_Face& theFace,
const Standard_Real theDefFace)
const Standard_Real theDefFace,
const TopTools_MutexForShapeProvider& theMutexProvider)
{
// gp_Pnt Pt;
BRep_Builder B;
@@ -1624,6 +1628,12 @@ void BRepMesh_FastDiscretFace::AddInShape(const TopoDS_Face& theFace,
const BRepMesh_PairOfPolygon& pair = It.Value();
const Handle(Poly_PolygonOnTriangulation)& NOD1 = pair.First();
const Handle(Poly_PolygonOnTriangulation)& NOD2 = pair.Last();
// lock mutex to prevent parallel change of the same data
Standard_Mutex* aMutex = theMutexProvider.GetMutex(It.Key());
Standard_Mutex::SentryNested (aMutex == NULL ? DummyMutex : *aMutex,
aMutex != NULL);
if ( NOD1 == NOD2 ) {
B.UpdateEdge(TopoDS::Edge(It.Key()), NullPoly, TOld,loc);
B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, T, loc);

View File

@@ -40,6 +40,7 @@
#include <TopExp_Explorer.hxx>
#include <TopAbs.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_MutexForShapeProvider.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TopoDS_Shape.hxx>
@@ -260,6 +261,7 @@ void BRepMesh_IncrementalMesh::Update(const TopoDS_Shape& S)
if (myInParallel)
{
#ifdef HAVE_TBB
myMesh->CreateMutexesForSubShapes(S, TopAbs_EDGE);
// mesh faces in parallel threads using TBB
tbb::parallel_for_each (aFaces.begin(), aFaces.end(), *myMesh.operator->());
#else
@@ -267,6 +269,7 @@ void BRepMesh_IncrementalMesh::Update(const TopoDS_Shape& S)
for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
myMesh->Process (*it);
#endif
myMesh->RemoveAllMutexes();
}
else
{