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:
parent
997ee30039
commit
28a676e105
@ -59,10 +59,10 @@ class ViewerFrameThread : public OpenThreads::Thread
|
||||
|
||||
~ViewerFrameThread()
|
||||
{
|
||||
cancel();
|
||||
while(isRunning())
|
||||
if (isRunning())
|
||||
{
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
cancel();
|
||||
join();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,11 @@ public:
|
||||
{
|
||||
_done = true;
|
||||
|
||||
while(isRunning()) OpenThreads::Thread::YieldCurrentThread();
|
||||
if (isRunning())
|
||||
{
|
||||
cancel();
|
||||
join();
|
||||
}
|
||||
}
|
||||
|
||||
void addFileName(const std::string& filename)
|
||||
|
@ -475,9 +475,10 @@ public:
|
||||
~NotifyThread()
|
||||
{
|
||||
_done = true;
|
||||
while(isRunning())
|
||||
if (isRunning())
|
||||
{
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
cancel();
|
||||
join();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,9 +365,6 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
thread.cancel();
|
||||
while (thread.isRunning())
|
||||
{
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
}
|
||||
thread.join();
|
||||
|
||||
}
|
||||
|
@ -177,8 +177,11 @@ CRenderingThread::CRenderingThread( cOSG* ptr )
|
||||
CRenderingThread::~CRenderingThread()
|
||||
{
|
||||
_done = true;
|
||||
while( isRunning() )
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
if (isRunning())
|
||||
{
|
||||
cancel();
|
||||
join();
|
||||
}
|
||||
}
|
||||
|
||||
void CRenderingThread::run()
|
||||
|
@ -201,7 +201,7 @@ class OSG_EXPORT OperationThread : public Referenced, public OpenThreads::Thread
|
||||
|
||||
void setDone(bool done);
|
||||
|
||||
bool getDone() const { return _done; }
|
||||
bool getDone() const { return _done!=0; }
|
||||
|
||||
/** Cancel this graphics thread.*/
|
||||
virtual int cancel();
|
||||
@ -212,7 +212,7 @@ class OSG_EXPORT OperationThread : public Referenced, public OpenThreads::Thread
|
||||
|
||||
observer_ptr<Object> _parent;
|
||||
|
||||
bool _done;
|
||||
OpenThreads::Atomic _done;
|
||||
|
||||
OpenThreads::Mutex _threadMutex;
|
||||
osg::ref_ptr<OperationQueue> _operationQueue;
|
||||
|
@ -456,6 +456,10 @@ Thread::~Thread()
|
||||
// Kill the thread when it is destructed
|
||||
//
|
||||
cancel();
|
||||
|
||||
// wait till the thread is stopped before finishing.
|
||||
join();
|
||||
|
||||
}
|
||||
|
||||
delete pd;
|
||||
|
@ -82,6 +82,8 @@ Thread::~Thread()
|
||||
{
|
||||
std::cout<<"Error: Thread "<< this <<" still running in destructor"<<std::endl;
|
||||
cancel();
|
||||
|
||||
join();
|
||||
}
|
||||
delete pd;
|
||||
_prvData = 0;
|
||||
|
@ -380,9 +380,7 @@ Thread::~Thread()
|
||||
//
|
||||
cancel();
|
||||
|
||||
while (pd->isRunning == true) {
|
||||
::usleep(1);
|
||||
}
|
||||
join();
|
||||
|
||||
}
|
||||
|
||||
|
@ -276,6 +276,8 @@ Thread::~Thread()
|
||||
std::cout<<"Error: Thread "<<this<<" still running in destructor"<<std::endl;
|
||||
pd->cancelMode = 0;
|
||||
cancel();
|
||||
|
||||
join();
|
||||
}
|
||||
|
||||
delete pd;
|
||||
|
@ -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;
|
||||
|
@ -662,14 +662,7 @@ int DatabasePager::DatabaseThread::cancel()
|
||||
break;
|
||||
}
|
||||
|
||||
// then wait for the the thread to stop running.
|
||||
while(isRunning())
|
||||
{
|
||||
// commenting out debug info as it was cashing crash on exit, presumable
|
||||
// due to OSG_NOTICE or std::cout destructing earlier than this destructor.
|
||||
// OSG_INFO<<"Waiting for DatabasePager::DatabaseThread to cancel"<<std::endl;
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
}
|
||||
join();
|
||||
|
||||
// _startThreadCalled = false;
|
||||
}
|
||||
|
@ -158,17 +158,11 @@ int ImagePager::ImageThread::cancel()
|
||||
// _databasePagerThreadBlock->release();
|
||||
|
||||
// then wait for the the thread to stop running.
|
||||
while(isRunning())
|
||||
{
|
||||
// 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 DatabasePager to cancel"<<std::endl;
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
}
|
||||
join();
|
||||
|
||||
// _startThreadCalled = false;
|
||||
}
|
||||
//std::cout<<"DatabasePager::~DatabasePager() stopped running"<<std::endl;
|
||||
//std::cout<<"ImagePager::cancel() thread stopped running"<<std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -152,19 +152,6 @@ RenderSurface::RenderSurface( void )
|
||||
|
||||
RenderSurface::~RenderSurface( void )
|
||||
{
|
||||
#if 0
|
||||
cancel();
|
||||
|
||||
_fini();
|
||||
|
||||
while (isRunning())
|
||||
{
|
||||
//std::cout << "waiting for RenderSurface to cancel"<<std::endl;
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
}
|
||||
|
||||
delete _threadReady;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,11 +95,10 @@ public:
|
||||
virtual void quit( bool waitForThreadToExit=true )
|
||||
{
|
||||
_done = true;
|
||||
if ( waitForThreadToExit )
|
||||
if (isRunning() && waitForThreadToExit)
|
||||
{
|
||||
while( isRunning() )
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
OSG_DEBUG<<"GifImageStream thread quitted"<<std::endl;
|
||||
cancel();
|
||||
join();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,13 +120,9 @@ void QuicktimeImageStream::quit(bool wiatForThreadToExit)
|
||||
OSG_DEBUG<<"Sending quit"<<this<<std::endl;
|
||||
setCmd(THREAD_QUIT);
|
||||
|
||||
if (wiatForThreadToExit)
|
||||
if (isRunning() && wiatForThreadToExit)
|
||||
{
|
||||
while(isRunning())
|
||||
{
|
||||
OSG_DEBUG<<"Waiting for QuicktimeImageStream to quit"<<this<<std::endl;
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
}
|
||||
join();
|
||||
OSG_DEBUG<<"QuicktimeImageStream has quit"<<this<<std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +73,10 @@ class LibVncImage : public osgWidget::VncImage
|
||||
virtual ~RfbThread()
|
||||
{
|
||||
_done = true;
|
||||
while(isRunning())
|
||||
if (isRunning())
|
||||
{
|
||||
OpenThreads::Thread::YieldCurrentThread();
|
||||
cancel();
|
||||
join();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user