Skip to content

Commit

Permalink
From Matthew Johnson-Roberson, "Small fix for operation thread to pro…
Browse files Browse the repository at this point in the history
…tect 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)
"
  • Loading branch information
robertosfield committed Jan 20, 2011
1 parent 2dc0247 commit 6d1944b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/osg/OperationThread
Expand Up @@ -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.*/
Expand Down
13 changes: 13 additions & 0 deletions src/osg/OperationThread.cpp
Expand Up @@ -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())
Expand Down

0 comments on commit 6d1944b

Please sign in to comment.