Added selective support for thread safe ref/unref such that the rendering

backend now doesn't use thread safe ref counting where multi-buffering exists.
This reduces the overhead of multi-threading.
This commit is contained in:
Robert Osfield
2006-05-02 15:52:46 +00:00
parent 67f56dfd77
commit a8c52a90f0
8 changed files with 29 additions and 11 deletions

View File

@@ -339,15 +339,16 @@ class RefMatrixd : public Object, public Matrixd
{
public:
RefMatrixd():Matrixd() {}
RefMatrixd( const Matrixd& other) : Matrixd(other) {}
RefMatrixd( const Matrixf& other) : Matrixd(other) {}
RefMatrixd():Object(false), Matrixd() {}
RefMatrixd( const Matrixd& other) : Object(false), Matrixd(other) {}
RefMatrixd( const Matrixf& other) : Object(false), Matrixd(other) {}
RefMatrixd( const RefMatrixd& other) : Object(other), Matrixd(other) {}
explicit RefMatrixd( Matrixd::value_type const * const def ):Matrixd(def) {}
explicit RefMatrixd( Matrixd::value_type const * const def ):Object(false), Matrixd(def) {}
RefMatrixd( Matrixd::value_type a00, Matrixd::value_type a01, Matrixd::value_type a02, Matrixd::value_type a03,
Matrixd::value_type a10, Matrixd::value_type a11, Matrixd::value_type a12, Matrixd::value_type a13,
Matrixd::value_type a20, Matrixd::value_type a21, Matrixd::value_type a22, Matrixd::value_type a23,
Matrixd::value_type a30, Matrixd::value_type a31, Matrixd::value_type a32, Matrixd::value_type a33):
Object(false),
Matrixd(a00, a01, a02, a03,
a10, a11, a12, a13,
a20, a21, a22, a23,

View File

@@ -340,15 +340,16 @@ class RefMatrixf : public Object, public Matrixf
{
public:
RefMatrixf():Matrixf() {}
RefMatrixf( const Matrixf& other) : Matrixf(other) {}
RefMatrixf( const Matrixd& other) : Matrixf(other) {}
RefMatrixf():Object(false), Matrixf() {}
RefMatrixf( const Matrixf& other) : Object(false), Matrixf(other) {}
RefMatrixf( const Matrixd& other) : Object(false), Matrixf(other) {}
RefMatrixf( const RefMatrixf& other) : Object(other), Matrixf(other) {}
explicit RefMatrixf( Matrixf::value_type const * const def ):Matrixf(def) {}
explicit RefMatrixf( Matrixf::value_type const * const def ):Object(false), Matrixf(def) {}
RefMatrixf( Matrixf::value_type a00, Matrixf::value_type a01, Matrixf::value_type a02, Matrixf::value_type a03,
Matrixf::value_type a10, Matrixf::value_type a11, Matrixf::value_type a12, Matrixf::value_type a13,
Matrixf::value_type a20, Matrixf::value_type a21, Matrixf::value_type a22, Matrixf::value_type a23,
Matrixf::value_type a30, Matrixf::value_type a31, Matrixf::value_type a32, Matrixf::value_type a33):
Object(false),
Matrixf(a00, a01, a02, a03,
a10, a11, a12, a13,
a20, a21, a22, a23,

View File

@@ -52,6 +52,8 @@ class OSG_EXPORT Object : public Referenced
concrete classes and can be constructed.*/
inline Object():Referenced(),_dataVariance(DYNAMIC) {}
inline explicit Object(bool threadSafeRefUnref):Referenced(threadSafeRefUnref),_dataVariance(DYNAMIC) {}
/** Copy constructor, optional CopyOp object can be used to control
* shallow vs deep copying of dynamic data.*/
Object(const Object&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);

View File

@@ -46,6 +46,8 @@ class OSG_EXPORT Referenced
Referenced();
explicit Referenced(bool threadSafeRefUnref);
Referenced(const Referenced&);
inline Referenced& operator = (const Referenced&) { return *this; }

View File

@@ -34,6 +34,7 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
inline RenderLeaf(osg::Drawable* drawable,osg::RefMatrix* projection,osg::RefMatrix* modelview, float depth=0.0f):
osg::Referenced(false),
_parent(0),
_drawable(drawable),
_projection(projection),
@@ -76,6 +77,7 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
/// disallow creation of blank RenderLeaf as this isn't useful.
RenderLeaf():
osg::Referenced(false),
_parent(0),
_drawable(0),
_projection(0),
@@ -83,7 +85,7 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
_depth(0.0f) {}
/// disallow copy construction.
RenderLeaf(const RenderLeaf&):osg::Referenced() {}
RenderLeaf(const RenderLeaf&):osg::Referenced(false) {}
/// disallow copy operator.
RenderLeaf& operator = (const RenderLeaf&) { return *this; }

View File

@@ -60,6 +60,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
StateGraph():
osg::Referenced(false),
_parent(NULL),
_stateset(NULL),
_depth(0),
@@ -70,6 +71,7 @@ class OSGUTIL_EXPORT StateGraph : public osg::Referenced
}
StateGraph(StateGraph* parent,const osg::StateSet* stateset):
osg::Referenced(false),
_parent(parent),
_stateset(stateset),
_depth(0),

View File

@@ -62,6 +62,14 @@ Referenced::Referenced():
if (s_useThreadSafeReferenceCounting) _refMutex = new OpenThreads::Mutex;
}
Referenced::Referenced(bool threadSafeRefUnref):
_refMutex(0),
_refCount(0),
_observers(0)
{
if (threadSafeRefUnref) _refMutex = new OpenThreads::Mutex;
}
Referenced::Referenced(const Referenced&):
_refMutex(0),
_refCount(0),

View File

@@ -992,7 +992,7 @@ void CullVisitor::apply(Projection& node)
_computed_zfar = -FLT_MAX;
ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(node.getMatrix());
ref_ptr<RefMatrix> matrix = createOrReuseMatrix(node.getMatrix());
pushProjectionMatrix(matrix.get());
//osg::notify(osg::INFO)<<"Push projection "<<*matrix<<std::endl;
@@ -1074,7 +1074,7 @@ void CullVisitor::apply(osg::CameraNode& camera)
setComputeNearFarMode( camera.getComputeNearFarMode());
osg::RefMatrix& originalModelView = getModelViewMatrix();
RefMatrix& originalModelView = getModelViewMatrix();
if (camera.getReferenceFrame()==osg::Transform::ABSOLUTE_RF)
{