diff --git a/include/osg/OperationsThread b/include/osg/OperationsThread index ad4b16b8b..154419d10 100644 --- a/include/osg/OperationsThread +++ b/include/osg/OperationsThread @@ -11,8 +11,8 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSG_OPERATIONSTHREAD -#define OSG_OPERATIONSTHREAD 1 +#ifndef OSG_OPERATIONTHREAD +#define OSG_OPERATIONTHREAD 1 #include #include @@ -23,6 +23,7 @@ #include #include +#include namespace osg { @@ -71,6 +72,8 @@ class Operation : virtual public Referenced bool _keep; }; +class OperationThread; + class OSG_EXPORT OperationQueue : public Referenced { public: @@ -103,25 +106,35 @@ class OSG_EXPORT OperationQueue : public Referenced /** Release operations block that is used to block threads that are waiting on an empty operations queue.*/ void releaseOperationsBlock(); + typedef std::set OperationThreads; + + /** Get the set of OperationThreads that are sharing this OperationQueue. */ + const OperationThreads& getOperationThreads() const { return _operationThreads; } protected: virtual ~OperationQueue(); - typedef std::list< ref_ptr > Operations; + friend class OperationThread; + + void addOperationThread(OperationThread* thread); + void removeOperationThread(OperationThread* thread); + + typedef std::list< osg::ref_ptr > Operations; OpenThreads::Mutex _operationsMutex; osg::ref_ptr _operationsBlock; Operations _operations; Operations::iterator _currentOperationIterator; + OperationThreads _operationThreads; }; /** GraphicsThread is a helper class for running OpenGL GraphicsOperation within a single thread assigned to a specific GraphicsContext.*/ -class OSG_EXPORT OperationsThread : public Referenced, public OpenThreads::Thread +class OSG_EXPORT OperationThread : public Referenced, public OpenThreads::Thread { public: - OperationsThread(); + OperationThread(); void setParent(Object* parent) { _parent = parent; } @@ -169,7 +182,7 @@ class OSG_EXPORT OperationsThread : public Referenced, public OpenThreads::Threa protected: - virtual ~OperationsThread(); + virtual ~OperationThread(); observer_ptr _parent; @@ -181,6 +194,8 @@ class OSG_EXPORT OperationsThread : public Referenced, public OpenThreads::Threa }; +typedef OperationThread OperationsThread; + } #endif diff --git a/src/osg/OperationsThread.cpp b/src/osg/OperationsThread.cpp index 0b22b1ab3..c44048d45 100644 --- a/src/osg/OperationsThread.cpp +++ b/src/osg/OperationsThread.cpp @@ -199,20 +199,30 @@ void OperationQueue::releaseOperationsBlock() } +void OperationQueue::addOperationThread(OperationThread* thread) +{ + _operationThreads.insert(thread); +} + +void OperationQueue::removeOperationThread(OperationThread* thread) +{ + _operationThreads.erase(thread); +} + ///////////////////////////////////////////////////////////////////////////// // -// OperationsThread +// OperationThread // -OperationsThread::OperationsThread(): +OperationThread::OperationThread(): osg::Referenced(true), _parent(0), _done(false) { - _operationQueue = new OperationQueue; + setOperationQueue(new OperationQueue); } -OperationsThread::~OperationsThread() +OperationThread::~OperationThread() { //osg::notify(osg::NOTICE)<<"Destructing graphics thread "< lock(_threadMutex); + + if (_operationQueue == opq) return; + + if (_operationQueue.valid()) _operationQueue->removeOperationThread(this); + _operationQueue = opq; + + if (_operationQueue.valid()) _operationQueue->addOperationThread(this); } -void OperationsThread::setDone(bool done) +void OperationThread::setDone(bool done) { if (_done==done) return; @@ -250,9 +267,9 @@ void OperationsThread::setDone(bool done) } } -int OperationsThread::cancel() +int OperationThread::cancel() { - osg::notify(osg::INFO)<<"Cancelling OperationsThread "<