rendered paste bodyIndex: libs/libmythupnp/threadpool.h===================================================================--- libs/libmythupnp/threadpool.h (revision 19769)+++ libs/libmythupnp/threadpool.h (working copy)@@ -66,6 +66,28 @@ ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// //+// WorkerEvent Class Declaration+//+/////////////////////////////////////////////////////////////////////////////+/////////////////////////////////////////////////////////////////////////////++class WorkerThread;+class WorkerEvent : public QObject+{+ Q_OBJECT++ public:+ WorkerEvent(WorkerThread *parent) : m_parent(parent) { }++ virtual void customEvent(QEvent *e);++ private:+ WorkerThread *m_parent;+};++/////////////////////////////////////////////////////////////////////////////+/////////////////////////////////////////////////////////////////////////////+// // WorkerThread Class Declaration // /////////////////////////////////////////////////////////////////////////////@@ -90,7 +112,9 @@ long m_nIdleTimeoutMS; bool m_bAllowTimeout; QTimer *m_timer;+ WorkerEvent *m_wakeup; + void WakeForWork(); protected: @@ -110,6 +134,7 @@ void SignalWork(); void TimeOut(); + friend class WorkerEvent; }; //////////////////////////////////////////////////////////////////////////////Index: libs/libmythupnp/threadpool.cpp===================================================================--- libs/libmythupnp/threadpool.cpp (revision 19769)+++ libs/libmythupnp/threadpool.cpp (working copy)@@ -21,6 +21,8 @@ // ////////////////////////////////////////////////////////////////////////////// +#include <QCoreApplication>+ #include <algorithm> using namespace std; @@ -118,6 +120,25 @@ ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// //+// WorkerEvent Class Implementation+//+/////////////////////////////////////////////////////////////////////////////+/////////////////////////////////////////////////////////////////////////////++/////////////////////////////////////////////////////////////////////////////+//+/////////////////////////////////////////////////////////////////////////////++void WorkerEvent::customEvent(QEvent *e)+{+ if (m_parent)+ m_parent->WakeForWork();+}+++/////////////////////////////////////////////////////////////////////////////+/////////////////////////////////////////////////////////////////////////////+// // WorkerThread Class Implementation // /////////////////////////////////////////////////////////////////////////////@@ -135,8 +156,7 @@ m_sName = sName; m_nIdleTimeoutMS = 60000; m_bAllowTimeout = false;- m_timer = new QTimer(this);- m_timer->setSingleShot(true);+ m_timer = NULL; } /////////////////////////////////////////////////////////////////////////////@@ -146,12 +166,9 @@ WorkerThread::~WorkerThread() { m_bTermRequested = true;- m_timer->stop(); quit(); wait();-- delete m_timer; } /////////////////////////////////////////////////////////////////////////////@@ -176,6 +193,21 @@ void WorkerThread::SignalWork() {+ if (!m_bInitialized)+ return;++cout << "posting event from: " << getpid() << endl;++ QCoreApplication::postEvent(m_wakeup, new QEvent(QEvent::User));+}++/////////////////////////////////////////////////////////////////////////////+//+/////////////////////////////////////////////////////////////////////////////++void WorkerThread::WakeForWork()+{+cout << "doing work in: " << getpid() << endl; try { ProcessWork();@@ -188,6 +220,7 @@ VERBOSE( VB_IMPORTANT, QString( "WorkerThread::Run( %1 ) - Unexpected Exception." ) .arg( m_sName )); }+ if (!m_bTermRequested) { m_pThreadPool->ThreadAvailable( this );@@ -201,16 +234,6 @@ void WorkerThread::SetTimeout( long nIdleTimeout ) { m_nIdleTimeoutMS = nIdleTimeout;-- if (m_nIdleTimeoutMS == -1 )- {- m_bAllowTimeout = false;- }- else- {- m_bAllowTimeout = true;- m_timer->start(m_nIdleTimeoutMS);- } } /////////////////////////////////////////////////////////////////////////////@@ -219,7 +242,8 @@ void WorkerThread::TimeOut() {- if (m_bAllowTimeout)+cout << "worker thread timedout\n";+ if (m_nIdleTimeoutMS > 0) quit(); } @@ -229,6 +253,11 @@ void WorkerThread::run( void ) {+ m_timer = new QTimer(this);+ m_timer->setSingleShot(true);++ m_wakeup = new WorkerEvent(this);+ m_mutex.lock(); m_bInitialized = true; m_mutex.unlock();@@ -236,7 +265,7 @@ m_Initialized.SetEvent(); connect(m_timer, SIGNAL(timeout()), this, SLOT(TimeOut()));- if (m_bAllowTimeout)+ if (m_nIdleTimeoutMS > 0) m_timer->start(m_nIdleTimeoutMS); exec();@@ -247,6 +276,9 @@ m_pThreadPool = NULL; } + delete m_timer;+ delete m_wakeup;+ VERBOSE( VB_UPNP, QString( "WorkerThread:Run - Exiting: %1" ).arg( m_sName )); }