Commit a7978ee2 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - now the FIFO (std::queue) is used properly and locked properly to...

[CHANGE] - now the FIFO (std::queue) is used properly and locked properly to do all the operations on childs in a WGEGroupNode
parent d1c81ed0
...@@ -69,8 +69,10 @@ void WGEGroupNode::remove( osg::ref_ptr< osg::Node > node ) ...@@ -69,8 +69,10 @@ void WGEGroupNode::remove( osg::ref_ptr< osg::Node > node )
void WGEGroupNode::clear() void WGEGroupNode::clear()
{ {
m_removeAll = true; boost::unique_lock<boost::shared_mutex> lock = boost::unique_lock<boost::shared_mutex>( m_childOperationQueueLock );
m_childOperationQueue.push( ChildOperation( false, osg::ref_ptr< osg::Node >() ) ); // this encodes the remove all feature
m_childOperationQueueDirty = true; m_childOperationQueueDirty = true;
lock.unlock();
} }
void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVisitor* nv ) void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
...@@ -85,26 +87,35 @@ void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVi ...@@ -85,26 +87,35 @@ void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVi
if ( rootNode->m_childOperationQueueDirty ) if ( rootNode->m_childOperationQueueDirty )
{ {
lock = boost::unique_lock<boost::shared_mutex>( rootNode->m_childOperationQueueLock ); lock = boost::unique_lock<boost::shared_mutex>( rootNode->m_childOperationQueueLock );
if ( rootNode->m_removeAll ) // insert/remove children which requested it
{ while ( !rootNode->m_childOperationQueue.empty() )
rootNode->removeChild( 0, rootNode->getNumChildren() );
}
else
{ {
// insert all children which requested it // remove or insert or remove all?
/*for ( std::set< osg::ref_ptr< osg::Node > >::iterator iter = rootNode->m_childRemovalQueue.begin(); if ( ( !rootNode->m_childOperationQueue.front().first ) && ( !rootNode->m_childOperationQueue.front().second ) )
iter != rootNode->m_childRemovalQueue.end();
++iter )
{ {
rootNode->removeChild( ( *iter ) ); // remove all
}*/ rootNode->removeChild( 0, rootNode->getNumChildren() );
}
else if ( rootNode->m_childOperationQueue.front().first )
{
// add specified child
rootNode->addChild( rootNode->m_childOperationQueue.front().second );
}
else
{
// remove specified child
rootNode->removeChild( rootNode->m_childOperationQueue.front().second );
}
// pop item
rootNode->m_childOperationQueue.pop();
} }
rootNode->dirtyBound(); rootNode->dirtyBound();
// all children added/removed -> clear // all children added/removed -> clear
rootNode->m_childOperationQueueDirty = false; rootNode->m_childOperationQueueDirty = false;
rootNode->m_removeAll = false; rootNode->m_removeAll = false;
//rootNode->m_childOperationQueue.clear();
lock.unlock(); lock.unlock();
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#ifndef WGEGROUPNODE_H #ifndef WGEGROUPNODE_H
#define WGEGROUPNODE_H #define WGEGROUPNODE_H
#include <stack> #include <queue>
#include <boost/thread.hpp> #include <boost/thread.hpp>
...@@ -113,7 +113,7 @@ protected: ...@@ -113,7 +113,7 @@ protected:
* Queue of childs that need to be added/removed during the next update cycle. It is a pair per operation, where the bool is denoting removal * Queue of childs that need to be added/removed during the next update cycle. It is a pair per operation, where the bool is denoting removal
* or insertion. * or insertion.
*/ */
std::stack< ChildOperation > m_childOperationQueue; std::queue< ChildOperation > m_childOperationQueue;
/** /**
* Lock used for inserting and removing childs into the child insertion/removal queue. * Lock used for inserting and removing childs into the child insertion/removal queue.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment