Replaced use of while(isRunning()) { YieldCurrentThread(); } style loops with use of join() to avoid false positives being reported by valgrind when using the helgrind tool for thread debugging.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14460 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2014-11-04 10:46:59 +00:00
parent 997ee30039
commit 28a676e105
17 changed files with 195 additions and 233 deletions

View File

@@ -264,7 +264,7 @@ void OperationQueue::removeOperationThread(OperationThread* thread)
OperationThread::OperationThread():
osg::Referenced(true),
_parent(0),
_done(false)
_done(0)
{
setOperationQueue(new OperationQueue);
}
@@ -293,9 +293,10 @@ void OperationThread::setOperationQueue(OperationQueue* opq)
void OperationThread::setDone(bool done)
{
if (_done==done) return;
unsigned d = done?0:1;
if (_done==d) return;
_done = true;
_done.exchange(d);
if (done)
{
@@ -322,7 +323,7 @@ int OperationThread::cancel()
if( isRunning() )
{
_done = true;
_done.exchange(1);
OSG_INFO<<" Doing cancel "<<this<<std::endl;
@@ -339,27 +340,7 @@ int OperationThread::cancel()
}
// then wait for the the thread to stop running.
while(isRunning())
{
#if 1
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_threadMutex);
if (_operationQueue.valid())
{
_operationQueue->releaseOperationsBlock();
// _operationQueue->releaseAllOperations();
}
if (_currentOperation.valid()) _currentOperation->release();
}
#endif
// commenting out debug info as it was cashing crash on exit, presumable
// due to OSG_NOTIFY or std::cout destructing earlier than this destructor.
OSG_DEBUG<<" Waiting for OperationThread to cancel "<<this<<std::endl;
OpenThreads::Thread::YieldCurrentThread();
}
join();
}
OSG_INFO<<" OperationThread::cancel() thread cancelled "<<this<<" isRunning()="<<isRunning()<<std::endl;