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:
@@ -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;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -54,7 +54,7 @@ int Thread::GetConcurrency()
|
||||
Thread::Thread()
|
||||
{
|
||||
if (!s_isInitialized) Init();
|
||||
|
||||
|
||||
QtThreadPrivateData* pd = new QtThreadPrivateData(this);
|
||||
pd->isRunning = false;
|
||||
pd->detached = false;
|
||||
@@ -65,7 +65,7 @@ Thread::Thread()
|
||||
pd->stackSize = 0;
|
||||
pd->threadPolicy = Thread::THREAD_SCHEDULE_DEFAULT;
|
||||
pd->threadPriority = Thread::THREAD_PRIORITY_DEFAULT;
|
||||
|
||||
|
||||
_prvData = static_cast<void*>(pd);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,8 @@ Thread::~Thread()
|
||||
{
|
||||
std::cout<<"Error: Thread "<< this <<" still running in destructor"<<std::endl;
|
||||
cancel();
|
||||
|
||||
join();
|
||||
}
|
||||
delete pd;
|
||||
_prvData = 0;
|
||||
@@ -90,7 +92,7 @@ Thread::~Thread()
|
||||
Thread* Thread::CurrentThread()
|
||||
{
|
||||
if (!s_isInitialized) Thread::Init();
|
||||
|
||||
|
||||
QtThreadPrivateData* pd = static_cast<QtThreadPrivateData*>(QThread::currentThread());
|
||||
return (pd ? pd->getMasterThread() : 0);
|
||||
}
|
||||
@@ -151,10 +153,10 @@ int Thread::start()
|
||||
{
|
||||
QtThreadPrivateData* pd = static_cast<QtThreadPrivateData*>(_prvData);
|
||||
pd->threadStartedBlock.reset();
|
||||
|
||||
|
||||
pd->setStackSize( pd->stackSize );
|
||||
pd->start();
|
||||
|
||||
|
||||
// wait till the thread has actually started.
|
||||
pd->threadStartedBlock.block();
|
||||
return 0;
|
||||
@@ -209,13 +211,13 @@ int Thread::testCancel()
|
||||
QtThreadPrivateData* pd = static_cast<QtThreadPrivateData*>(_prvData);
|
||||
if (!pd->cancelled)
|
||||
return 0;
|
||||
|
||||
|
||||
if (pd->cancelMode == 2)
|
||||
return -1;
|
||||
|
||||
|
||||
if (pd!=QThread::currentThread())
|
||||
return -1;
|
||||
|
||||
|
||||
throw QtThreadCanceled();
|
||||
}
|
||||
|
||||
@@ -232,7 +234,7 @@ int Thread::cancel()
|
||||
{
|
||||
if (pd->cancelMode == 2)
|
||||
return -1;
|
||||
|
||||
|
||||
pd->cancelled = true;
|
||||
if (pd->cancelMode == 1)
|
||||
{
|
||||
@@ -294,7 +296,7 @@ int Thread::setSchedulePriority(ThreadPriority priority)
|
||||
{
|
||||
QtThreadPrivateData* pd = static_cast<QtThreadPrivateData*>(_prvData);
|
||||
pd->threadPriority = priority;
|
||||
|
||||
|
||||
if (pd->isRunning)
|
||||
pd->applyPriority();
|
||||
return 0;
|
||||
@@ -374,7 +376,7 @@ int Thread::setProcessorAffinity(unsigned int cpunum)
|
||||
QtThreadPrivateData* pd = static_cast<QtThreadPrivateData*>(_prvData);
|
||||
pd->cpunum = cpunum;
|
||||
if (!pd->isRunning) return 0;
|
||||
|
||||
|
||||
// FIXME:
|
||||
// Qt doesn't have a platform-independent thread affinity method at present.
|
||||
// Does it automatically configure threads on different processors, or we have to do it ourselves?
|
||||
@@ -391,7 +393,7 @@ void Thread::printSchedulingInfo()
|
||||
{
|
||||
QtThreadPrivateData* pd = static_cast<QtThreadPrivateData*>(_prvData);
|
||||
std::cout << "Thread "<< pd->getMasterThread() <<" priority: ";
|
||||
|
||||
|
||||
switch (pd->threadPriority)
|
||||
{
|
||||
case Thread::THREAD_PRIORITY_MAX:
|
||||
@@ -453,7 +455,7 @@ int OpenThreads::GetNumberOfProcessors()
|
||||
int OpenThreads::SetProcessorAffinityOfCurrentThread(unsigned int cpunum)
|
||||
{
|
||||
if (cpunum<0) return -1;
|
||||
|
||||
|
||||
Thread::Init();
|
||||
Thread* thread = Thread::CurrentThread();
|
||||
if (thread)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -156,10 +156,10 @@ void ThreadPrivateActions::StartThread(void *data)
|
||||
pd->stackSizeLocked = true;
|
||||
|
||||
pd->isRunning = true;
|
||||
|
||||
|
||||
// release the thread that created this thread.
|
||||
pd->threadStartedBlock.release();
|
||||
|
||||
|
||||
thread->run();
|
||||
|
||||
pd->isRunning = false;
|
||||
@@ -380,9 +380,7 @@ Thread::~Thread()
|
||||
//
|
||||
cancel();
|
||||
|
||||
while (pd->isRunning == true) {
|
||||
::usleep(1);
|
||||
}
|
||||
join();
|
||||
|
||||
}
|
||||
|
||||
@@ -520,7 +518,7 @@ int Thread::start() {
|
||||
//
|
||||
int Thread::startThread()
|
||||
{
|
||||
if (_prvData) return start();
|
||||
if (_prvData) return start();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
@@ -808,7 +806,7 @@ int OpenThreads::SetProcessorAffinityOfCurrentThread(unsigned int cpunum)
|
||||
Thread::Init();
|
||||
|
||||
Thread* thread = Thread::CurrentThread();
|
||||
if (thread)
|
||||
if (thread)
|
||||
{
|
||||
return thread->setProcessorAffinity(cpunum);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace OpenThreads {
|
||||
static unsigned int __stdcall StartThread(void *data) {
|
||||
|
||||
Thread *thread = static_cast<Thread *>(data);
|
||||
|
||||
|
||||
Win32ThreadPrivateData *pd =
|
||||
static_cast<Win32ThreadPrivateData *>(thread->_prvData);
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace OpenThreads {
|
||||
SetThreadSchedulingParams(thread);
|
||||
|
||||
pd->isRunning = true;
|
||||
|
||||
|
||||
// release the thread that created this thread.
|
||||
pd->threadStartedBlock.release();
|
||||
|
||||
@@ -276,10 +276,12 @@ Thread::~Thread()
|
||||
std::cout<<"Error: Thread "<<this<<" still running in destructor"<<std::endl;
|
||||
pd->cancelMode = 0;
|
||||
cancel();
|
||||
|
||||
join();
|
||||
}
|
||||
|
||||
delete pd;
|
||||
|
||||
|
||||
_prvData = 0;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -337,11 +339,11 @@ int Thread::start() {
|
||||
//-------------------------------------------------------------------------
|
||||
// Prohibit the stack size from being changed.
|
||||
// (bb 5/13/2005) it actually doesn't matter.
|
||||
// 1) usually setStackSize()/start() sequence is serialized.
|
||||
// 2) if not than we're in trouble anyway - nothing is protected
|
||||
// 1) usually setStackSize()/start() sequence is serialized.
|
||||
// 2) if not than we're in trouble anyway - nothing is protected
|
||||
// pd->stackSizeLocked = true;
|
||||
unsigned int ID;
|
||||
|
||||
|
||||
pd->threadStartedBlock.reset();
|
||||
|
||||
pd->tid.set( (void*)_beginthreadex(NULL,static_cast<unsigned>(pd->stackSize),ThreadPrivateActions::StartThread,static_cast<void *>(this),CREATE_SUSPENDED,&ID));
|
||||
@@ -362,7 +364,7 @@ int Thread::start() {
|
||||
|
||||
int Thread::startThread()
|
||||
{
|
||||
if (_prvData) return start();
|
||||
if (_prvData) return start();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
@@ -685,7 +687,7 @@ int OpenThreads::SetProcessorAffinityOfCurrentThread(unsigned int cpunum)
|
||||
Thread::Init();
|
||||
|
||||
Thread* thread = Thread::CurrentThread();
|
||||
if (thread)
|
||||
if (thread)
|
||||
{
|
||||
return thread->setProcessorAffinity(cpunum);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,9 +98,9 @@ class LibVncImage : public osgWidget::VncImage
|
||||
{
|
||||
// OSG_NOTICE<<"Timed out"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double currentTime = _image->time();
|
||||
double timeBeforeIdle = 0.1;
|
||||
|
||||
@@ -115,7 +116,7 @@ class LibVncImage : public osgWidget::VncImage
|
||||
//OSG_NOTICE<<"New: Should still be active"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} while (!_done && !testCancel());
|
||||
}
|
||||
|
||||
@@ -321,8 +322,8 @@ rfbBool LibVncImage::resizeImage(rfbClient* client)
|
||||
void LibVncImage::updateImage(rfbClient* client,int x,int y,int w,int h)
|
||||
{
|
||||
LibVncImage* image = (LibVncImage*)(rfbClientGetClientData(client, 0));
|
||||
|
||||
image->dirty();
|
||||
|
||||
image->dirty();
|
||||
}
|
||||
|
||||
bool LibVncImage::sendPointerEvent(int x, int y, int buttonMask)
|
||||
@@ -348,9 +349,9 @@ bool LibVncImage::sendKeyEvent(int key, bool keyDown)
|
||||
|
||||
void LibVncImage::setFrameLastRendered(const osg::FrameStamp*)
|
||||
{
|
||||
|
||||
|
||||
_timeOfLastRender = time();
|
||||
|
||||
|
||||
// release block
|
||||
_inactiveBlock->release();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user