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<OpenThreads::Mutex> 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)
"
This commit is contained in:
Robert Osfield 2011-01-20 12:32:20 +00:00
parent 2dc0247bd9
commit 6d1944b9e2
2 changed files with 15 additions and 2 deletions

View File

@ -105,10 +105,10 @@ class OSG_EXPORT OperationQueue : public Referenced
osg::ref_ptr<Operation> 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<unsigned int>(_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.*/

View File

@ -55,6 +55,19 @@ OperationQueue::~OperationQueue()
{
}
bool OperationQueue::empty()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex);
return _operations.empty();
}
unsigned int OperationQueue::getNumOperationsInQueue()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex);
return static_cast<unsigned int>(_operations.size());
}
ref_ptr<Operation> OperationQueue::getNextOperation(bool blockIfEmpty)
{
if (blockIfEmpty && _operations.empty())