summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Hurlbut <ghurlbut@mythtv.org>2011-01-12 07:11:36 (GMT)
committer Gavin Hurlbut <ghurlbut@mythtv.org>2011-01-16 00:23:54 (GMT)
commit945c6731794590de8c58c638c0a1b1e40076dea2 (patch)
treecdd415f2131d8be1b9c14e388bba641a2165e261
parent798359f673e108f5b345c99b6f671648171bf2d9 (diff)
Make the worker threads clean up properly
Seems our WorkerThreads never came off the m_lstThreads deque, and also never hit the destructor. Fixed this in the ThreadTerminating function, and using a "deleteLater" Also added a bit more logging to help track the issue. (cherry picked from commit 6a1b7e32f15740bd9eb7263973cd3c126e3a44bd)
-rw-r--r--mythtv/libs/libmythupnp/threadpool.cpp50
1 files changed, 26 insertions, 24 deletions
diff --git a/mythtv/libs/libmythupnp/threadpool.cpp b/mythtv/libs/libmythupnp/threadpool.cpp
index 0656c49..9059dc1 100644
--- a/mythtv/libs/libmythupnp/threadpool.cpp
+++ b/mythtv/libs/libmythupnp/threadpool.cpp
@@ -367,15 +367,13 @@ WorkerThread *ThreadPool::GetWorkerThread()
// --------------------------------------------------------------
m_mList.lock();
+ if ( m_lstAvailableThreads.size() > 0)
{
- if ( m_lstAvailableThreads.size() > 0)
- {
- pThread = m_lstAvailableThreads.front();
- m_lstAvailableThreads.pop_front();
- }
-
- nThreadCount = m_lstThreads.size();
+ pThread = m_lstAvailableThreads.front();
+ m_lstAvailableThreads.pop_front();
}
+
+ nThreadCount = m_lstThreads.size();
m_mList.unlock();
if (pThread == NULL)
@@ -411,6 +409,7 @@ WorkerThread *ThreadPool::GetWorkerThread()
WorkerThread *ThreadPool::AddWorkerThread( bool bMakeAvailable, long nTimeout )
{
QString sName = m_sName + "_WorkerThread";
+ long nThreadCount;
VERBOSE( VB_UPNP, QString( "ThreadPool:AddWorkerThread - %1" ).arg( sName ));
@@ -428,23 +427,21 @@ WorkerThread *ThreadPool::AddWorkerThread( bool bMakeAvailable, long nTimeout )
// ------------------------------------------------------
m_mList.lock();
- {
+ m_lstThreads.push_back( pThread );
+ nThreadCount = m_lstThreads.size();
- m_lstThreads.push_back( pThread );
-
- if (bMakeAvailable)
- {
- m_lstAvailableThreads.push_back( pThread );
+ VERBOSE(VB_IMPORTANT|VB_EXTRA, QString("ThreadPool:%1: thread pool size %2") .arg(m_sName) .arg(nThreadCount));
- m_threadAvail.wakeAll();
- }
+ if (bMakeAvailable)
+ {
+ m_lstAvailableThreads.push_back( pThread );
+ m_threadAvail.wakeAll();
}
m_mList.unlock();
}
else
{
-
// ------------------------------------------------------
// It's taking longer than 5 seconds to initialize this thread....
// give up on it.
@@ -478,16 +475,21 @@ void ThreadPool::ThreadAvailable ( WorkerThread *pThread )
void ThreadPool::ThreadTerminating ( WorkerThread *pThread )
{
+ long nThreadCount;
+
m_mList.lock();
- {
- WorkerThreadList::iterator it =
- find(m_lstAvailableThreads.begin(),
- m_lstAvailableThreads.end(), pThread);
- m_lstAvailableThreads.erase(it);
+ WorkerThreadList::iterator it = find(m_lstAvailableThreads.begin(),
+ m_lstAvailableThreads.end(), pThread);
+ m_lstAvailableThreads.erase(it);
+
+ it = find(m_lstThreads.begin(), m_lstThreads.end(), pThread);
+ m_lstThreads.erase(it);
+
+ nThreadCount = m_lstThreads.size();
+ VERBOSE(VB_IMPORTANT|VB_EXTRA, QString("ThreadPool:%1: thread pool size %2") .arg(m_sName) .arg(nThreadCount));
+
+ pThread->deleteLater();
- // Need to leave in m_lstThreads so that we can
- // delete the ptr in destructor
- }
m_mList.unlock();
}