Added mutex locking add addParents/removeParents in Drawable, Node and StateSet.

This commit is contained in:
Robert Osfield 2007-08-31 20:14:36 +00:00
parent 1bc6d0bae4
commit 86e998f64c
4 changed files with 70 additions and 10 deletions

View File

@ -59,6 +59,9 @@ class OSG_EXPORT Referenced
/** Get whether a mutex is used to ensure ref() and unref() are thread safe.*/
bool getThreadSafeRefUnref() const { return _refMutex!=0; }
/** Get the mutex used to ensure thread safety of ref()/unref(). */
OpenThreads::Mutex* getRefMutex() const { return _refMutex; }
/** Increment the reference count by one, indicating that
this object has another pointer which is referencing it.*/
inline void ref() const;

View File

@ -313,13 +313,32 @@ void Drawable::computeDataVariance()
void Drawable::addParent(osg::Node* node)
{
_parents.push_back(node);
if (getRefMutex())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*getRefMutex());
_parents.push_back(node);
}
else
{
_parents.push_back(node);
}
}
void Drawable::removeParent(osg::Node* node)
{
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
if (pitr!=_parents.end()) _parents.erase(pitr);
if (getRefMutex())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*getRefMutex());
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
if (pitr!=_parents.end()) _parents.erase(pitr);
}
else
{
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
if (pitr!=_parents.end()) _parents.erase(pitr);
}
}

View File

@ -95,13 +95,32 @@ Node::~Node()
void Node::addParent(osg::Group* node)
{
_parents.push_back(node);
if (getRefMutex())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*getRefMutex());
_parents.push_back(node);
}
else
{
_parents.push_back(node);
}
}
void Node::removeParent(osg::Group* node)
{
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
if (pitr!=_parents.end()) _parents.erase(pitr);
if (getRefMutex())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*getRefMutex());
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
if (pitr!=_parents.end()) _parents.erase(pitr);
}
else
{
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
if (pitr!=_parents.end()) _parents.erase(pitr);
}
}
void Node::accept(NodeVisitor& nv)

View File

@ -78,7 +78,8 @@ bool osg::isTextureMode(StateAttribute::GLMode mode)
return getTextureGLModeSet().isTextureMode(mode);
}
StateSet::StateSet()
StateSet::StateSet():
Object(true)
{
_renderingHint = DEFAULT_BIN;
@ -247,14 +248,32 @@ void StateSet::computeDataVariance()
void StateSet::addParent(osg::Object* object)
{
// osg::notify(osg::INFO)<<"Adding parent"<<std::endl;
if (getRefMutex())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*getRefMutex());
_parents.push_back(object);
_parents.push_back(object);
}
else
{
_parents.push_back(object);
}
}
void StateSet::removeParent(osg::Object* object)
{
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object);
if (pitr!=_parents.end()) _parents.erase(pitr);
if (getRefMutex())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*getRefMutex());
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object);
if (pitr!=_parents.end()) _parents.erase(pitr);
}
else
{
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object);
if (pitr!=_parents.end()) _parents.erase(pitr);
}
}
int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const