0023260: Regression: Instability in parallel incmesh on Linux.
[occt.git] / src / TopTools / TopTools_MutexForShapeProvider.cxx
CommitLineData
d00cba63 1// Created on: 2012-06-27
2// Created by: Dmitry BOBYLEV
3// Copyright (c) 2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20#include <TopTools_MutexForShapeProvider.hxx>
21
f67d0512 22#include <Standard_Mutex.hxx>
d00cba63 23#include <TopoDS_Iterator.hxx>
24
f67d0512 25
d00cba63 26// macro to compare two types of shapes
27#define SAMETYPE(x,y) ((x) == (y))
28#define LESSCOMPLEX(x,y) ((x) > (y))
29
30//=======================================================================
31//function : TopTools_MutexForShapeProvider
32//purpose :
33//=======================================================================
34TopTools_MutexForShapeProvider::TopTools_MutexForShapeProvider()
35{
36}
37
38
39//=======================================================================
40//function : ~TopTools_MutexForShapeProvider
41//purpose :
42//=======================================================================
43TopTools_MutexForShapeProvider::~TopTools_MutexForShapeProvider()
44{
45 RemoveAllMutexes();
46}
47
48//=======================================================================
49//function : CreateMutexesForSubShapes
50//purpose :
51//=======================================================================
52void TopTools_MutexForShapeProvider::CreateMutexesForSubShapes(const TopoDS_Shape& theShape,
53 const TopAbs_ShapeEnum theType)
54{
55 if (LESSCOMPLEX(theShape.ShapeType(), theType))
56 return;
57
58 for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next())
59 {
60 const TopoDS_Shape& aShape = anIt.Value();
61 if (LESSCOMPLEX(theType, aShape.ShapeType()))
62 {
63 CreateMutexesForSubShapes(aShape, theType);
64 }
65 else if (SAMETYPE(theType, aShape.ShapeType()))
66 {
67 CreateMutexForShape(aShape);
68 }
69 }
70}
71
72//=======================================================================
73//function : CreateMutexForShape
74//purpose :
75//=======================================================================
76void TopTools_MutexForShapeProvider::CreateMutexForShape(const TopoDS_Shape& theShape)
77{
f67d0512 78 if (!myMap.IsBound(theShape.TShape()))
d00cba63 79 {
80 Standard_Mutex* aMutex = new Standard_Mutex();
f67d0512 81 myMap.Bind(theShape.TShape(), aMutex);
d00cba63 82 }
83}
84
85//=======================================================================
86//function : CreateMutexForShape
87//purpose :
88//=======================================================================
89Standard_Mutex* TopTools_MutexForShapeProvider::GetMutex(const TopoDS_Shape& theShape) const
90{
f67d0512 91 if (myMap.IsBound(theShape.TShape()))
d00cba63 92 {
f67d0512 93 Standard_Mutex* aMutex = myMap.Find(theShape.TShape());
d00cba63 94 return aMutex;
95 }
96 else
97 {
98 return NULL;
99 }
100}
101
102//=======================================================================
103//function : RemoveAllMutexes
104//purpose :
105//=======================================================================
106void TopTools_MutexForShapeProvider::RemoveAllMutexes()
107{
f67d0512 108 for (NCollection_DataMap<TopoDS_Shape, Standard_Mutex *>::Iterator anIter;
d00cba63 109 anIter.More(); anIter.Next())
110 {
111 delete anIter.Value();
112 }
113 myMap.Clear();
114}