Hi Richard,

I have made some changes to Referenced, OpenThreads and the various
addParent/removeParent codes to make sure that mutex is used to
protect access to these methods even when atomic ref counting is
enabled.

The solution I opted for was to have a static
Referenced::getGlobalReferencedMutex() method that which is used get
Referenced::getRefMutext() when using atomic ref counting, rather than
the NULL that was be passed back previously.   To keep the
addParent/removeParent() codes simpler and more reliable I have
introduced an OpenThreads::ScopedPointerLock() which takes a pointer
to a mutex rather than a reference to a mutex.  This removes the
if/else block, so the code now looks like:

void Node::addParent(osg::Group* node)
{
    OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex());

    _parents.push_back(node);
}

void Node::removeParent(osg::Group* node)
{
    OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex());

    ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
    if (pitr!=_parents.end()) _parents.erase(pitr);
}

The StateAttribute::addParent/removeParent wasn't previous protected
by a mutex lock so I've added the above usage style to it as well.

These changes should hopefully fix the lack of thread safety
associated with adding/removing objects parents.

Richard, could you please try out the svn/trunk version and see if
these changes fix things at your end.

Robert.
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to