1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0022939: Make B-Spline internal cache thread-safe to be used in multy-threaded mode

Internal cache in classes implementing b-spline curves and surface in Geom and Geom2d packages is protected from possible concurrency by mutex (added as a class field in each instance).
This commit is contained in:
abv 2012-05-04 15:51:20 +04:00 committed by azn
parent 870f239379
commit 83ada95bb5
6 changed files with 177 additions and 152 deletions

View File

@ -124,7 +124,8 @@ uses Array1OfInteger from TColStd,
Vec from gp, Vec from gp,
BSplKnotDistribution from GeomAbs, BSplKnotDistribution from GeomAbs,
Geometry from Geom, Geometry from Geom,
Shape from GeomAbs Shape from GeomAbs,
Mutex from Standard
raises ConstructionError from Standard, raises ConstructionError from Standard,
@ -1035,4 +1036,6 @@ fields
maxderivinv : Real from Standard; maxderivinv : Real from Standard;
maxderivinvok : Boolean from Standard; maxderivinvok : Boolean from Standard;
myMutex : Mutex from Standard;
-- protected bspline-cache
end; end;

View File

@ -36,6 +36,7 @@
#include <Standard_OutOfRange.hxx> #include <Standard_OutOfRange.hxx>
#include <Standard_DomainError.hxx> #include <Standard_DomainError.hxx>
#include <Standard_RangeError.hxx> #include <Standard_RangeError.hxx>
#include <Standard_Mutex.hxx>
#define POLES (poles->Array1()) #define POLES (poles->Array1())
#define KNOTS (knots->Array1()) #define KNOTS (knots->Array1())
@ -105,36 +106,36 @@ Standard_Integer Geom_BSplineCurve::Degree () const
//purpose : //purpose :
//======================================================================= //=======================================================================
void Geom_BSplineCurve::D0 ( const Standard_Real U, void Geom_BSplineCurve::D0(const Standard_Real U, gp_Pnt& P) const
gp_Pnt& P) const
{ {
Standard_Real NewU = U ; Standard_Real NewU(U);
PeriodicNormalization(NewU) ; PeriodicNormalization(NewU);
if (!IsCacheValid(NewU))
{
Geom_BSplineCurve * MyCurve = (Geom_BSplineCurve *) this ;
MyCurve->ValidateCache(NewU) ;
}
if (rational) {
Geom_BSplineCurve* MyCurve = (Geom_BSplineCurve *) this;
Standard_Mutex::Sentry aSentry(MyCurve->myMutex);
if(!IsCacheValid(NewU))
MyCurve->ValidateCache(NewU);
if(rational)
{
BSplCLib::CacheD0(NewU, BSplCLib::CacheD0(NewU,
deg, deg,
parametercache, parametercache,
spanlenghtcache, spanlenghtcache,
(cachepoles->Array1()), cachepoles->Array1(),
cacheweights->Array1(), cacheweights->Array1(),
P) ; P);
} }
else { else
{
BSplCLib::CacheD0(NewU, BSplCLib::CacheD0(NewU,
deg, deg,
parametercache, parametercache,
spanlenghtcache, spanlenghtcache,
(cachepoles->Array1()), cachepoles->Array1(),
*((TColStd_Array1OfReal*) NULL), *((TColStd_Array1OfReal*) NULL),
P) ; P);
} }
} }
@ -147,32 +148,36 @@ void Geom_BSplineCurve::D1 (const Standard_Real U,
gp_Pnt& P, gp_Pnt& P,
gp_Vec& V1) const gp_Vec& V1) const
{ {
Standard_Real NewU = U ; Standard_Real NewU(U);
PeriodicNormalization(NewU) ; PeriodicNormalization(NewU);
if (!IsCacheValid(NewU))
{ Geom_BSplineCurve* MyCurve = (Geom_BSplineCurve *) this;
Geom_BSplineCurve * MyCurve = (Geom_BSplineCurve *) this ; Standard_Mutex::Sentry aSentry(MyCurve->myMutex);
MyCurve->ValidateCache(NewU) ;
} if(!IsCacheValid(NewU))
if (rational) { MyCurve->ValidateCache(NewU);
if(rational)
{
BSplCLib::CacheD1(NewU, BSplCLib::CacheD1(NewU,
deg, deg,
parametercache, parametercache,
spanlenghtcache, spanlenghtcache,
(cachepoles->Array1()), cachepoles->Array1(),
cacheweights->Array1(), cacheweights->Array1(),
P, P,
V1) ; V1);
} }
else { else
{
BSplCLib::CacheD1(NewU, BSplCLib::CacheD1(NewU,
deg, deg,
parametercache, parametercache,
spanlenghtcache, spanlenghtcache,
(cachepoles->Array1()), cachepoles->Array1(),
*((TColStd_Array1OfReal*) NULL), *((TColStd_Array1OfReal*) NULL),
P, P,
V1) ; V1);
} }
} }
@ -181,20 +186,22 @@ Standard_Real NewU = U ;
//purpose : //purpose :
//======================================================================= //=======================================================================
void Geom_BSplineCurve::D2 (const Standard_Real U , void Geom_BSplineCurve::D2(const Standard_Real U,
gp_Pnt& P , gp_Pnt& P,
gp_Vec& V1, gp_Vec& V1,
gp_Vec& V2 ) const gp_Vec& V2) const
{ {
Standard_Real NewU(U);
Standard_Real NewU = U ; PeriodicNormalization(NewU);
PeriodicNormalization(NewU) ;
if (!IsCacheValid(NewU)) Geom_BSplineCurve* MyCurve = (Geom_BSplineCurve *) this;
{ Standard_Mutex::Sentry aSentry(MyCurve->myMutex);
Geom_BSplineCurve * MyCurve = (Geom_BSplineCurve *) this ;
MyCurve->ValidateCache(NewU) ; if(!IsCacheValid(NewU))
} MyCurve->ValidateCache(NewU);
if (rational) {
if(rational)
{
BSplCLib::CacheD2(NewU, BSplCLib::CacheD2(NewU,
deg, deg,
parametercache, parametercache,
@ -203,7 +210,7 @@ void Geom_BSplineCurve::D2 (const Standard_Real U ,
cacheweights->Array1(), cacheweights->Array1(),
P, P,
V1, V1,
V2) ; V2);
} }
else { else {
BSplCLib::CacheD2(NewU, BSplCLib::CacheD2(NewU,
@ -214,7 +221,7 @@ void Geom_BSplineCurve::D2 (const Standard_Real U ,
*((TColStd_Array1OfReal*) NULL), *((TColStd_Array1OfReal*) NULL),
P, P,
V1, V1,
V2) ; V2);
} }
} }
@ -223,21 +230,24 @@ void Geom_BSplineCurve::D2 (const Standard_Real U ,
//purpose : //purpose :
//======================================================================= //=======================================================================
void Geom_BSplineCurve::D3 (const Standard_Real U , void Geom_BSplineCurve::D3(const Standard_Real U,
gp_Pnt& P , gp_Pnt& P,
gp_Vec& V1, gp_Vec& V1,
gp_Vec& V2, gp_Vec& V2,
gp_Vec& V3 ) const gp_Vec& V3) const
{ {
Standard_Real NewU = U ; Standard_Real NewU(U);
PeriodicNormalization(NewU) ; PeriodicNormalization(NewU);
if (!IsCacheValid(NewU))
{ Geom_BSplineCurve* MyCurve = (Geom_BSplineCurve *) this;
Geom_BSplineCurve * MyCurve = (Geom_BSplineCurve *) this ; Standard_Mutex::Sentry aSentry(MyCurve->myMutex);
MyCurve->ValidateCache(NewU) ;
} if(!IsCacheValid(NewU))
if (rational) { MyCurve->ValidateCache(NewU);
if(rational)
{
BSplCLib::CacheD3(NewU, BSplCLib::CacheD3(NewU,
deg, deg,
parametercache, parametercache,
@ -249,12 +259,13 @@ Standard_Real NewU = U ;
V2, V2,
V3) ; V3) ;
} }
else { else
{
BSplCLib::CacheD3(NewU, BSplCLib::CacheD3(NewU,
deg, deg,
parametercache, parametercache,
spanlenghtcache, spanlenghtcache,
(cachepoles->Array1()), cachepoles->Array1(),
*((TColStd_Array1OfReal*) NULL), *((TColStd_Array1OfReal*) NULL),
P, P,
V1, V1,

View File

@ -153,8 +153,8 @@ uses Array1OfInteger from TColStd,
BSplKnotDistribution from GeomAbs, BSplKnotDistribution from GeomAbs,
Curve from Geom, Curve from Geom,
Geometry from Geom, Geometry from Geom,
Shape from GeomAbs Shape from GeomAbs,
Mutex from Standard
raises ConstructionError from Standard, raises ConstructionError from Standard,
DimensionError from Standard, DimensionError from Standard,
@ -1487,4 +1487,7 @@ fields
vmaxderivinv : Real from Standard; vmaxderivinv : Real from Standard;
maxderivinvok : Boolean from Standard; maxderivinvok : Boolean from Standard;
myMutex : Mutex from Standard;
-- protected bsplinesurface-cache
end; end;

View File

@ -48,6 +48,7 @@
#include <Standard_DimensionError.hxx> #include <Standard_DimensionError.hxx>
#include <Standard_ConstructionError.hxx> #include <Standard_ConstructionError.hxx>
#include <Standard_NotImplemented.hxx> #include <Standard_NotImplemented.hxx>
#include <Standard_Mutex.hxx>
#define POLES (poles->Array2()) #define POLES (poles->Array2())
#define WEIGHTS (weights->Array2()) #define WEIGHTS (weights->Array2())
@ -111,21 +112,19 @@ Standard_Boolean Geom_BSplineSurface::IsCNv
//purpose : //purpose :
//======================================================================= //=======================================================================
void Geom_BSplineSurface::D0 (const Standard_Real U, void Geom_BSplineSurface::D0(const Standard_Real U,
const Standard_Real V, const Standard_Real V,
gp_Pnt& P ) const gp_Pnt& P) const
{ {
Standard_Real new_u = U, Standard_Real new_u(U), new_v(V);
new_v = V ; PeriodicNormalization(new_u, new_v);
PeriodicNormalization(new_u,
new_v) ; Geom_BSplineSurface* MySurface = (Geom_BSplineSurface *) this;
if (!IsCacheValid(new_u, Standard_Mutex::Sentry aSentry(MySurface->myMutex);
new_v))
{ if(!IsCacheValid(new_u, new_v))
Geom_BSplineSurface * my_surface = (Geom_BSplineSurface *) this ; MySurface->ValidateCache(new_u, new_v);
my_surface->ValidateCache(new_u,
new_v) ;
}
Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2, Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
uspanlenght_11 = ucachespanlenght/2, uspanlenght_11 = ucachespanlenght/2,
vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2, vparameter_11 = (2*vcacheparameter + vcachespanlenght)/2,
@ -164,23 +163,20 @@ void Geom_BSplineSurface::D0 (const Standard_Real U,
//purpose : //purpose :
//======================================================================= //=======================================================================
void Geom_BSplineSurface::D1 (const Standard_Real U, void Geom_BSplineSurface::D1(const Standard_Real U,
const Standard_Real V, const Standard_Real V,
gp_Pnt& P, gp_Pnt& P,
gp_Vec& D1U, gp_Vec& D1U,
gp_Vec& D1V) const gp_Vec& D1V) const
{ {
Standard_Real new_u = U, Standard_Real new_u(U), new_v(V);
new_v = V ; PeriodicNormalization(new_u, new_v);
PeriodicNormalization(new_u,
new_v) ; Geom_BSplineSurface* MySurface = (Geom_BSplineSurface *) this;
if (!IsCacheValid(new_u, Standard_Mutex::Sentry aSentry(MySurface->myMutex);
new_v))
{ if(!IsCacheValid(new_u, new_v))
Geom_BSplineSurface * my_surface = (Geom_BSplineSurface *) this ; MySurface->ValidateCache(new_u, new_v);
my_surface->ValidateCache(new_u,
new_v) ;
}
Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2, Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
uspanlenght_11 = ucachespanlenght/2, uspanlenght_11 = ucachespanlenght/2,
@ -235,18 +231,14 @@ void Geom_BSplineSurface::D2 (const Standard_Real U,
gp_Vec& D2V, gp_Vec& D2V,
gp_Vec& D2UV) const gp_Vec& D2UV) const
{ {
Standard_Real new_u(U), new_v(V);
PeriodicNormalization(new_u, new_v);
Standard_Real new_u = U, Geom_BSplineSurface* MySurface = (Geom_BSplineSurface *) this;
new_v = V ; Standard_Mutex::Sentry aSentry(MySurface->myMutex);
PeriodicNormalization(new_u,
new_v) ; if(!IsCacheValid(new_u, new_v))
if (!IsCacheValid(new_u, MySurface->ValidateCache(new_u, new_v);
new_v))
{
Geom_BSplineSurface * my_surface = (Geom_BSplineSurface *) this ;
my_surface->ValidateCache(new_u,
new_v) ;
}
Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2, Standard_Real uparameter_11 = (2*ucacheparameter + ucachespanlenght)/2,
uspanlenght_11 = ucachespanlenght/2, uspanlenght_11 = ucachespanlenght/2,

View File

@ -129,8 +129,8 @@ uses Array1OfInteger from TColStd,
Vec2d from gp, Vec2d from gp,
BSplKnotDistribution from GeomAbs, BSplKnotDistribution from GeomAbs,
Geometry from Geom2d, Geometry from Geom2d,
Shape from GeomAbs Shape from GeomAbs,
Mutex from Standard
raises ConstructionError from Standard, raises ConstructionError from Standard,
DimensionError from Standard, DimensionError from Standard,
@ -1044,4 +1044,7 @@ fields
maxderivinv : Real from Standard; maxderivinv : Real from Standard;
maxderivinvok : Boolean from Standard; maxderivinvok : Boolean from Standard;
myMutex : Mutex from Standard;
-- protected bspline-cache
end; end;

View File

@ -35,6 +35,7 @@
#include <Standard_OutOfRange.hxx> #include <Standard_OutOfRange.hxx>
#include <Standard_DomainError.hxx> #include <Standard_DomainError.hxx>
#include <Standard_RangeError.hxx> #include <Standard_RangeError.hxx>
#include <Standard_Mutex.hxx>
#define POLES (poles->Array1()) #define POLES (poles->Array1())
#define KNOTS (knots->Array1()) #define KNOTS (knots->Array1())
@ -109,14 +110,17 @@ Standard_Integer Geom2d_BSplineCurve::Degree () const
void Geom2d_BSplineCurve::D0 ( const Standard_Real U, void Geom2d_BSplineCurve::D0 ( const Standard_Real U,
gp_Pnt2d& P) const gp_Pnt2d& P) const
{ {
Standard_Real NewU = U ; Standard_Real NewU(U);
PeriodicNormalization(NewU) ; PeriodicNormalization(NewU);
if (!IsCacheValid(NewU)) {
Geom2d_BSplineCurve * MyCurve = (Geom2d_BSplineCurve *) this ; Geom2d_BSplineCurve* MyCurve = (Geom2d_BSplineCurve *) this;
MyCurve->ValidateCache(NewU) ; Standard_Mutex::Sentry aSentry(MyCurve->myMutex);
}
if (!IsCacheValid(NewU))
MyCurve->ValidateCache(NewU);
if ( rational ) { if(rational)
{
BSplCLib::CacheD0(NewU, BSplCLib::CacheD0(NewU,
deg, deg,
parametercache, parametercache,
@ -146,14 +150,17 @@ void Geom2d_BSplineCurve::D1 (const Standard_Real U,
gp_Pnt2d& P, gp_Pnt2d& P,
gp_Vec2d& V1) const gp_Vec2d& V1) const
{ {
Standard_Real NewU = U ; Standard_Real NewU(U);
PeriodicNormalization(NewU) ; PeriodicNormalization(NewU);
if (!IsCacheValid(NewU)) {
Geom2d_BSplineCurve * MyCurve = (Geom2d_BSplineCurve *) this ;
MyCurve->ValidateCache(NewU) ;
}
if ( rational ) { Geom2d_BSplineCurve* MyCurve = (Geom2d_BSplineCurve *) this;
Standard_Mutex::Sentry aSentry(MyCurve->myMutex);
if (!IsCacheValid(NewU))
MyCurve->ValidateCache(NewU);
if(rational)
{
BSplCLib::CacheD1(NewU, BSplCLib::CacheD1(NewU,
deg, deg,
parametercache, parametercache,
@ -185,14 +192,17 @@ void Geom2d_BSplineCurve::D2 (const Standard_Real U ,
gp_Vec2d& V1, gp_Vec2d& V1,
gp_Vec2d& V2 ) const gp_Vec2d& V2 ) const
{ {
Standard_Real NewU = U ; Standard_Real NewU(U);
PeriodicNormalization(NewU) ; PeriodicNormalization(NewU);
if (!IsCacheValid(NewU)) {
Geom2d_BSplineCurve * MyCurve = (Geom2d_BSplineCurve *) this ; Geom2d_BSplineCurve* MyCurve = (Geom2d_BSplineCurve *) this;
MyCurve->ValidateCache(NewU) ; Standard_Mutex::Sentry aSentry(MyCurve->myMutex);
}
if (!IsCacheValid(NewU))
MyCurve->ValidateCache(NewU);
if ( rational ) { if(rational)
{
BSplCLib::CacheD2(NewU, BSplCLib::CacheD2(NewU,
deg, deg,
parametercache, parametercache,
@ -227,14 +237,17 @@ void Geom2d_BSplineCurve::D3 (const Standard_Real U ,
gp_Vec2d& V2, gp_Vec2d& V2,
gp_Vec2d& V3 ) const gp_Vec2d& V3 ) const
{ {
Standard_Real NewU = U ; Standard_Real NewU(U);
PeriodicNormalization(NewU) ; PeriodicNormalization(NewU);
if (!IsCacheValid(NewU)) {
Geom2d_BSplineCurve * MyCurve = (Geom2d_BSplineCurve *) this ;
MyCurve->ValidateCache(NewU) ;
}
if ( rational ) { Geom2d_BSplineCurve* MyCurve = (Geom2d_BSplineCurve *) this;
Standard_Mutex::Sentry aSentry(MyCurve->myMutex);
if (!IsCacheValid(NewU))
MyCurve->ValidateCache(NewU);
if(rational)
{
BSplCLib::CacheD3(NewU, BSplCLib::CacheD3(NewU,
deg, deg,
parametercache, parametercache,