From 6d1944b9e2f629b79248a451930f5a987398f61b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 20 Jan 2011 12:32:20 +0000 Subject: [PATCH] From Matthew Johnson-Roberson, "Small fix for operation thread to protect the access to _operations vector by functions getNumOperationsInQueue() and empty(). It is simply an addition of OpenThreads::ScopedLock lock(_operationsMutex); to protect against accessing while writing which was segfaulting in VPB specifically in void ThreadPool::run(osg::Operation* op) in the waiting loop while (_operationQueue->getNumOperationsInQueue() >= _maxNumberOfOperationsInQueue) " --- include/osg/OperationThread | 4 ++-- src/osg/OperationThread.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/osg/OperationThread b/include/osg/OperationThread index e3fda41f7..6d3ef2c6e 100644 --- a/include/osg/OperationThread +++ b/include/osg/OperationThread @@ -105,10 +105,10 @@ class OSG_EXPORT OperationQueue : public Referenced osg::ref_ptr getNextOperation(bool blockIfEmpty = false); /** Return true if the operation queue is empty. */ - bool empty() const { return _operations.empty(); } + bool empty(); /** Return the num of pending operations that are sitting in the OperationQueue.*/ - unsigned int getNumOperationsInQueue() const { return static_cast(_operations.size()); } + unsigned int getNumOperationsInQueue(); /** Add operation to end of OperationQueue, this will be * executed by the operation thread once this operation gets to the head of the queue.*/ diff --git a/src/osg/OperationThread.cpp b/src/osg/OperationThread.cpp index 98276a1d6..5835928d9 100644 --- a/src/osg/OperationThread.cpp +++ b/src/osg/OperationThread.cpp @@ -55,6 +55,19 @@ OperationQueue::~OperationQueue() { } +bool OperationQueue::empty() +{ + + OpenThreads::ScopedLock lock(_operationsMutex); + return _operations.empty(); +} + +unsigned int OperationQueue::getNumOperationsInQueue() +{ + OpenThreads::ScopedLock lock(_operationsMutex); + return static_cast(_operations.size()); +} + ref_ptr OperationQueue::getNextOperation(bool blockIfEmpty) { if (blockIfEmpty && _operations.empty())