[Opalvoip-svn] SF.net SVN: opalvoip:[34841] opal/trunk
Brought to you by:
csoutheren,
rjongbloed
From: <rjo...@us...> - 2016-05-27 06:24:39
|
Revision: 34841 http://sourceforge.net/p/opalvoip/code/34841 Author: rjongbloed Date: 2016-05-27 06:24:37 +0000 (Fri, 27 May 2016) Log Message: ----------- Merged revision(s) 34805-34839 from opal/branches/v3_16: Added PThread::WaitAndDelete() to handle thread termination management which is very common repeated code. Also, to aid debugging, this new function will, when termination exceeds a timeout, do stack walks of the thread being terminated and the thread waiting on termination. Modified Paths: -------------- opal/trunk/samples/callgen/main.cxx opal/trunk/samples/openphone/main.cxx opal/trunk/src/ep/opalmixer.cxx opal/trunk/src/ep/pcss.cxx opal/trunk/src/h323/gkclient.cxx opal/trunk/src/h323/gkserver.cxx opal/trunk/src/h323/peclient.cxx opal/trunk/src/im/msrp.cxx opal/trunk/src/lids/capi_ep.cxx opal/trunk/src/lids/lidep.cxx opal/trunk/src/lids/lidpluginmgr.cxx opal/trunk/src/opal/console_mgr.cxx opal/trunk/src/opal/manager.cxx opal/trunk/src/opal/mediasession.cxx opal/trunk/src/opal/patch.cxx opal/trunk/src/opal/pres_ent.cxx opal/trunk/src/opal/transports.cxx Property Changed: ---------------- opal/trunk/ Index: opal/trunk =================================================================== --- opal/trunk 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk 2016-05-27 06:24:37 UTC (rev 34841) Property changes on: opal/trunk ___________________________________________________________________ Modified: svn:mergeinfo ## -10,7 +10,7 ## /opal/branches/v3_10:25182-29485,30896,32927-32928,32933 /opal/branches/v3_12:28489-31709 /opal/branches/v3_14:31505-33613 -/opal/branches/v3_16:34090-34804 +/opal/branches/v3_16:34090-34839 /opal/branches/v3_2:21143,21220,21227,21253,21455 /opal/branches/v3_4:21060,21062,21088,21092,21111,21113,21115,21119,21143,21148,21151-21152,21155,21158,21184,21188,21253,21265-21266,21283-21284,21298,21300,21303,21307,21309,21311,21327,21331,21333,21359,21367,21369,21488,21556,21564-21565,21568,21570,21620,21625,21631,21748,21751,21756,21759,21761,21767,21770,22246,23044,23140,23143,23286 /opal/branches/v3_6:22169,22178,22184,22186,22197,22204,22216,22251,22253,22255,22258,22260,22291,22296,22300,22306,22308,22313,22319,22336,22353,22358,22436,22447,22449,22497,22511,22517,22519-22521,22527,22536,22538,22589,22596,22599,22617,22620,22622,22630,22640,22655,22675,22682,22726-22728,22730,22733,22738,22745-22746,22800,22820-22821,22842,22844-22845,22851,22853,22889,22896,22902,22904,22906,22918,22924,22928,22946,22965,22967,22976,22978,22980,22982,22994,23028,23123,23125-23126,23128,23157,23165,23173,23175,23183,23294,23341,23465,23467,23474,23521,23829,24346,24809 \ No newline at end of property Modified: opal/trunk/samples/callgen/main.cxx =================================================================== --- opal/trunk/samples/callgen/main.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/samples/callgen/main.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -705,8 +705,9 @@ } if (m_tone.IsEmpty()) { - m_tone.SetSampleRate(mediaStream.GetMediaFormat().GetClockRate()); - m_tone.Generate('-', 440, 0, 20); // 20ms of middle A + OpalMediaFormat mediaFormat = mediaStream.GetMediaFormat(); + m_tone.SetSampleRate(mediaFormat.GetClockRate()); + m_tone.Generate('-', 440, 0, std::max(mediaFormat.GetFrameTime()/mediaFormat.GetTimeUnits(), 20U)); // at least 20ms of middle A } PINDEX bytesLeft = (m_tone.GetSize() - m_toneOffset) / 2; Modified: opal/trunk/samples/openphone/main.cxx =================================================================== --- opal/trunk/samples/openphone/main.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/samples/openphone/main.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -5880,12 +5880,8 @@ if (m_TestVideoDisplay != NULL) m_TestVideoDisplay->Close(); - if (m_TestVideoThread != NULL) - m_TestVideoThread->WaitForTermination(); + PThread::WaitAndDelete(m_TestVideoThread); - delete m_TestVideoThread; - m_TestVideoThread = NULL; - delete m_TestVideoDisplay; m_TestVideoDisplay = NULL; Modified: opal/trunk/src/ep/opalmixer.cxx =================================================================== --- opal/trunk/src/ep/opalmixer.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/ep/opalmixer.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -223,20 +223,7 @@ void OpalBaseMixer::StopPushThread(bool lock) { - if (lock) - m_mutex.Wait(); - - PThread * thread = m_workerThread; - m_workerThread = NULL; - m_threadRunning = false; - - m_mutex.Signal(); - - if (thread != NULL) { - PTRACE(4, "Waiting for push thread " << *thread << " to terminate"); - PAssert(thread->WaitForTermination(5000), PSTRSTRM("Mixer worker thread " << *thread << " took too long to terminate.")); - delete thread; - } + PThread::WaitAndDelete(m_workerThread, 5000, &m_mutex, lock); } Modified: opal/trunk/src/ep/pcss.cxx =================================================================== --- opal/trunk/src/ep/pcss.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/ep/pcss.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -510,13 +510,8 @@ void OpalPCSSConnection::OnReleased() { - if (m_ringbackThread != NULL) { - PTRACE(4, "OnRelease stopping ringback thread"); - m_ringbackStop.Signal(); - m_ringbackThread->WaitForTermination(); - delete m_ringbackThread; - m_ringbackThread = NULL; - } + m_ringbackStop.Signal(); + PThread::WaitAndDelete(m_ringbackThread); StopReadUserInput(); @@ -763,9 +758,7 @@ PTRACE(3, "Stopping user input thread."); m_userInputChannel->Close(); - m_userInputThread->WaitForTermination(); - delete m_userInputThread; - m_userInputThread = NULL; + PThread::WaitAndDelete(m_userInputThread); if (m_userInputAutoDelete) delete m_userInputChannel; m_userInputChannel = NULL; Modified: opal/trunk/src/h323/gkclient.cxx =================================================================== --- opal/trunk/src/h323/gkclient.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/h323/gkclient.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -333,13 +333,9 @@ void H323Gatekeeper::StopChannel() { - if (m_monitorThread != NULL) { - m_monitorRunning = false; - m_monitorTickle.Signal(); - PAssert(m_monitorThread->WaitForTermination(10000), "Gatekeeper monitor thread did not stop"); - delete m_monitorThread; - m_monitorThread = 0; - } + m_monitorRunning = false; + m_monitorTickle.Signal(); + PThread::WaitAndDelete(m_monitorThread); H323Transactor::StopChannel(); } Modified: opal/trunk/src/h323/gkserver.cxx =================================================================== --- opal/trunk/src/h323/gkserver.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/h323/gkserver.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -2655,8 +2655,7 @@ H323GatekeeperServer::~H323GatekeeperServer() { monitorExit.Signal(); - PAssert(monitorThread->WaitForTermination(10000), "Gatekeeper monitor thread did not terminate!"); - delete monitorThread; + PThread::WaitAndDelete(m_monitorThread); #if OPAL_H501 delete m_peerElement; #endif Modified: opal/trunk/src/h323/peclient.cxx =================================================================== --- opal/trunk/src/h323/peclient.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/h323/peclient.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -209,8 +209,7 @@ if (monitor != NULL) { monitorStop = true; monitorTickle.Signal(); - monitor->WaitForTermination(); - delete monitor; + PThread::WaitAndDelete(monitor); } StopChannel(); Modified: opal/trunk/src/im/msrp.cxx =================================================================== --- opal/trunk/src/im/msrp.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/im/msrp.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -518,11 +518,8 @@ { PWaitAndSignal m(mutex); - if (m_listenerThread != NULL) { - m_listenerSocket.Close(); - m_listenerThread->WaitForTermination(); - delete m_listenerThread; - } + m_listenerSocket.Close(); + PThread::WaitAndDelete(m_listenerThread); } @@ -714,12 +711,9 @@ OpalMSRPManager::Connection::~Connection() { - if (m_handlerThread != NULL) { - m_running = false; - m_handlerThread->WaitForTermination(); - delete m_handlerThread; - m_handlerThread = NULL; - } + m_running = false; + PThread::WaitAndDelete(m_handlerThread); + delete m_protocol; m_protocol = NULL; PTRACE(3, "MSRP\tDestroying connection"); Modified: opal/trunk/src/lids/capi_ep.cxx =================================================================== --- opal/trunk/src/lids/capi_ep.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/lids/capi_ep.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -554,16 +554,13 @@ OpalCapiEndPoint::~OpalCapiEndPoint() { - if (m_thread != NULL) { - PTRACE(4, "LID EP\tAwaiting monitor thread termination " << GetPrefixName()); - OpalCapiFunctions::ApplID oldId = m_applicationId; - m_applicationId = 0; + OpalCapiFunctions::ApplID oldId = m_applicationId; + m_applicationId = 0; + if (oldId != 0) m_capi->RELEASE(oldId); - m_thread->WaitForTermination(); - delete m_thread; - m_thread = NULL; - } + PThread::WaitAndDelete(m_thread); + delete m_capi; PTRACE(4, "CAPI\tOpalCapiEndPoint destroyed"); Modified: opal/trunk/src/lids/lidep.cxx =================================================================== --- opal/trunk/src/lids/lidep.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/lids/lidep.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -63,21 +63,16 @@ OpalLineEndPoint::~OpalLineEndPoint() { - if(NULL != monitorThread) - { - PTRACE(4, "LID EP\tAwaiting monitor thread termination " << GetPrefixName()); - exitFlag.Signal(); - monitorThread->WaitForTermination(); - delete monitorThread; - monitorThread = NULL; + exitFlag.Signal(); + PThread::WaitAndDelete(monitorThread); - /* remove all lines which has been added with AddLine or AddLinesFromDevice - RemoveAllLines can be invoked only after the monitorThread has been destroyed, - indeed, the monitor thread may called some function such as vpb_get_event_ch_async which may - throw an exception if the line handle is no longer valid - */ - RemoveAllLines(); - } + /* remove all lines which has been added with AddLine or AddLinesFromDevice + RemoveAllLines can be invoked only after the monitorThread has been destroyed, + indeed, the monitor thread may called some function such as vpb_get_event_ch_async which may + throw an exception if the line handle is no longer valid + */ + RemoveAllLines(); + PTRACE(4, "LID EP\tOpalLineEndPoint " << GetPrefixName() << " destroyed"); } @@ -501,14 +496,9 @@ { PTRACE(3, "LID Con\tOnReleased " << *this); - if (handlerThread != NULL && PThread::Current() != handlerThread) { - PTRACE(4, "LID Con\tAwaiting handler thread termination " << *this); - // Stop the signalling handler thread - SetUserInput(PString()); // Break out of ReadUserInput - handlerThread->WaitForTermination(); - delete handlerThread; - handlerThread = NULL; - } + // Stop the signalling handler thread + SetUserInput(PString()); // Break out of ReadUserInput + PThread::WaitAndDelete(handlerThread); if (line.IsTerminal()) { if (line.IsOffHook()) { Modified: opal/trunk/src/lids/lidpluginmgr.cxx =================================================================== --- opal/trunk/src/lids/lidpluginmgr.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/lids/lidpluginmgr.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -1016,12 +1016,8 @@ void OpalPluginLID::StopTonePlayerThread() { // Stop previous tone, if running - if (m_tonePlayer != NULL) { - m_stopTone.Signal(); - m_tonePlayer->WaitForTermination(1000); - delete m_tonePlayer; - m_tonePlayer = NULL; - } + m_stopTone.Signal(); + PThread::WaitAndDelete(m_tonePlayer); } Modified: opal/trunk/src/opal/console_mgr.cxx =================================================================== --- opal/trunk/src/opal/console_mgr.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/opal/console_mgr.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -1655,13 +1655,9 @@ void OpalConsolePCSSEndPoint::ShutDown() { - if (m_ringThread != NULL) { - m_ringState = e_RingShutDown; - m_ringSignal.Signal(); - m_ringThread->WaitForTermination(); - delete m_ringThread; - m_ringThread = NULL; - } + m_ringState = e_RingShutDown; + m_ringSignal.Signal(); + PThread::WaitAndDelete(m_ringThread); OpalPCSSEndPoint::ShutDown(); } Modified: opal/trunk/src/opal/manager.cxx =================================================================== --- opal/trunk/src/opal/manager.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/opal/manager.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -409,11 +409,8 @@ #endif // Shut down the cleaner thread - if (m_garbageCollector != NULL) { - m_garbageCollectExit.Signal(); - m_garbageCollector->WaitForTermination(); - delete m_garbageCollector; - } + m_garbageCollectExit.Signal(); + PThread::WaitAndDelete(m_garbageCollector); // Clean up any calls that the cleaner thread missed on the way out GarbageCollection(); Modified: opal/trunk/src/opal/mediasession.cxx =================================================================== --- opal/trunk/src/opal/mediasession.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/opal/mediasession.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -745,9 +745,17 @@ for (vector<Transport>::iterator it = m_subchannels.begin(); it != m_subchannels.end(); ++it) { if (it->m_channel != NULL) { PChannel * base = it->m_channel->GetBaseReadChannel(); - if (base != NULL) + if (base != NULL) { + PTRACE(4, *this << it->m_subchannel << " closing."); base->Close(); + } + else { + PTRACE(3, *this << it->m_subchannel << " already closed."); + } } + else { + PTRACE(3, *this << it->m_subchannel << " not created."); + } } UnlockReadOnly(); @@ -802,15 +810,14 @@ void OpalMediaTransport::InternalStop() { - PTRACE(4, *this << "stopping " << m_subchannels.size() << "subchannels."); + if (m_subchannels.empty()) + return; + + PTRACE(4, *this << "stopping " << m_subchannels.size() << " subchannels."); InternalClose(); - for (vector<Transport>::iterator it = m_subchannels.begin(); it != m_subchannels.end(); ++it) { - if (it->m_thread != NULL) { - PAssert(it->m_thread->WaitForTermination(10000), "RTP thread failed to terminate"); - delete it->m_thread; - } - } + for (vector<Transport>::iterator it = m_subchannels.begin(); it != m_subchannels.end(); ++it) + PThread::WaitAndDelete(it->m_thread); LockReadWrite(); for (vector<Transport>::iterator it = m_subchannels.begin(); it != m_subchannels.end(); ++it) Modified: opal/trunk/src/opal/patch.cxx =================================================================== --- opal/trunk/src/opal/patch.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/opal/patch.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -179,20 +179,7 @@ void OpalMediaPatch::StopThread() { - m_patchThreadMutex.Wait(); - PThread * thread = m_patchThread; - m_patchThread = NULL; - m_patchThreadMutex.Signal(); - - if (thread == NULL) - return; - - if (!thread->IsSuspended()) { - PTRACE(4, "Waiting for media patch thread to stop " << *this); - PAssert(thread->WaitForTermination(10000), "Media patch thread not terminated."); - } - - delete thread; + PThread::WaitAndDelete(m_patchThread, 10000, &m_patchThreadMutex); } Modified: opal/trunk/src/opal/pres_ent.cxx =================================================================== --- opal/trunk/src/opal/pres_ent.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/opal/pres_ent.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -589,14 +589,9 @@ void OpalPresentityWithCommandThread::StopThread() { - if (m_threadRunning && m_thread != NULL) { - PTRACE(4, "Stopping command thread " << *m_thread); - m_threadRunning = false; - m_commandQueueSync.Signal(); - PAssert(m_thread->WaitForTermination(5000), "Could not terminate presentity command thread"); - delete m_thread; - m_thread = NULL; - } + m_threadRunning = false; + m_commandQueueSync.Signal(); + PThread::WaitAndDelete(m_thread); } Modified: opal/trunk/src/opal/transports.cxx =================================================================== --- opal/trunk/src/opal/transports.cxx 2016-05-27 06:18:43 UTC (rev 34840) +++ opal/trunk/src/opal/transports.cxx 2016-05-27 06:24:37 UTC (rev 34841) @@ -650,31 +650,12 @@ } -static void WaitForTransportThread(PThread * thread, const OpalEndPoint & endpoint) -{ - if (thread == NULL) - return; - - if (PThread::Current() == thread) { - thread->SetAutoDelete(); - return; - } - - PTimeInterval timeout(0, 2); // Seconds of grace - timeout += endpoint.GetManager().GetSignalingTimeout(); - PAssert(thread->WaitForTermination(timeout), "Transport/Listener thread did not terminate"); - delete thread; -} - - void OpalListener::CloseWait() { PTRACE(3, "Stopping listening thread on " << GetLocalAddress()); Close(); - PThread * exitingThread = m_thread; - m_thread = NULL; - WaitForTransportThread(exitingThread, m_endpoint); + PThread::WaitAndDelete(m_thread, m_endpoint.GetManager().GetSignalingTimeout()+2000); } @@ -1096,7 +1077,7 @@ m_keepAliveTimer.Stop(); - WaitForTransportThread(exitingThread, m_endpoint); + PThread::WaitAndDelete(exitingThread, m_endpoint.GetManager().GetSignalingTimeout()+2000); } @@ -1136,10 +1117,7 @@ { PTRACE_CONTEXT_ID_TO(thrd); - if (m_thread != NULL) { - PAssert(m_thread->WaitForTermination(10000), "Transport not terminated when reattaching thread"); - delete m_thread; - } + PThread::WaitAndDelete(m_thread); m_thread = thrd; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |