1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2013 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _BOPDS_Col_HeaderFile
16 #define _BOPDS_Col_HeaderFile
18 #include <Standard_Macro.hxx>
19 #include <Standard_NotImplemented.hxx>
22 // On Windows, function TryEnterCriticalSection has appeared in Windows NT
23 // and is surrounded by #ifdef in MS VC++ 7.1 headers.
24 // Thus to use it we need to define appropriate macro saying that we wil
25 // run on Windows NT 4.0 at least
26 #if ((defined(_WIN32) || defined(__WIN32__)) && !defined(_WIN32_WINNT))
27 #define _WIN32_WINNT 0x0501
33 #define flexible_range blocked_range
34 #define flexible_for parallel_for
38 #define flexible_range serial_range
39 #define flexible_for serial_for
41 //=======================================================================
42 //class : serial_range
44 //=======================================================================
45 template <class Type> class serial_range {
47 serial_range(const Type& aBegin,
49 : myBegin(aBegin), myEnd(aEnd) {
55 const Type& begin() const{
59 const Type& end() const{
68 //=======================================================================
69 //function : serial_for
71 //=======================================================================
72 template<typename Range, typename Body>
73 static void serial_for( const Range& range, const Body& body ) {
74 body.operator()(range);
76 #endif // not HAVE_TBB
78 // 2. Implementation of Functors/Starters
82 //=======================================================================
83 //class : BOPCol_TBBFunctor
85 //=======================================================================
86 template <class TypeSolver,
87 class TypeSolverVector> class BOPCol_TBBFunctor {
90 BOPCol_TBBFunctor(TypeSolverVector& aV)
94 ~BOPCol_TBBFunctor() {
97 void operator()( const flexible_range<Standard_Integer>& aBR ) const{
98 Standard_Integer i, iBeg, iEnd;
100 TypeSolverVector& aV=*myPV;
104 for(i=iBeg; i!=iEnd; ++i) {
105 TypeSolver& aSolver=aV(i);
112 TypeSolverVector* myPV;
114 //=======================================================================
115 //class : BOPCol_TBBCnt
117 //=======================================================================
118 template <class TypeFunctor,
119 class TypeSolverVector> class BOPCol_TBBCnt {
121 //-------------------------------
124 static void Perform(const Standard_Boolean bRunParallel,
125 TypeSolverVector& aV) {
127 TypeFunctor aFunctor(aV);
128 Standard_Integer aNb=aV.Extent();
133 flexible_for(flexible_range<Standard_Integer>(0,aNb), aFunctor);
136 catch( captured_exception& ) {
137 Standard_NotImplemented::Raise("");
140 Standard_NotImplemented::Raise("");
142 #else // not HAVE_TBB
143 flexible_for(flexible_range<Standard_Integer>(0,aNb), aFunctor);
147 aFunctor.operator()(flexible_range<Standard_Integer>(0,aNb));
152 // 2.2. Context dependent version
155 //=======================================================================
156 //class : BOPCol_TBBContextFunctor
158 //=======================================================================
159 template <class TypeSolver,
160 class TypeSolverVector,
162 typename TN> class BOPCol_TBBContextFunctor {
165 BOPCol_TBBContextFunctor(TypeSolverVector& aV)
169 ~BOPCol_TBBContextFunctor() {
172 void SetContext(TypeContext& aCtx) {
176 void operator()( const flexible_range<Standard_Integer>& aBR ) const{
177 Standard_Integer i, iBeg, iEnd;
180 if (myContext.IsNull()) {
182 (NCollection_BaseAllocator::CommonBaseAllocator());
188 TypeSolverVector& aV=*myPV;
192 for(i=iBeg; i!=iEnd; ++i) {
193 TypeSolver& aSolver=aV(i);
195 aSolver.SetContext(aCtx);
201 TypeSolverVector* myPV;
202 TypeContext myContext;
206 //=======================================================================
207 //class : BOPCol_TBBContextCnt
209 //=======================================================================
210 template <class TypeFunctor,
211 class TypeSolverVector,
212 class TypeContext> class BOPCol_TBBContextCnt {
214 //-------------------------------
217 static void Perform(const Standard_Boolean bRunParallel,
218 TypeSolverVector& aV,
221 TypeFunctor aFunctor(aV);
222 Standard_Integer aNb=aV.Extent();
227 flexible_for(flexible_range<Standard_Integer>(0,aNb), aFunctor);
230 catch(captured_exception& ) {
231 //cout<<" captured_exception: " << ex.what() << endl;
232 Standard_NotImplemented::Raise("");
235 Standard_NotImplemented::Raise("");
237 #else // not HAVE_TBB
238 flexible_for(flexible_range<Standard_Integer>(0,aNb), aFunctor);
242 aFunctor.SetContext(aCtx);
243 aFunctor.operator()(flexible_range<Standard_Integer>(0,aNb));