Ticket #4301: upnp_threading_r15096.patch
File upnp_threading_r15096.patch, 9.0 KB (added by , 16 years ago) |
---|
-
libs/libmythupnp/threadpool.h
63 63 64 64 CEvent m_Initialized; 65 65 bool m_bInitialized; 66 66 67 67 ThreadPool *m_pThreadPool; 68 68 69 boolm_bTermRequested;69 volatile bool m_bTermRequested; 70 70 QString m_sName; 71 71 72 72 long m_nIdleTimeoutMS; … … 78 78 virtual void run(); 79 79 virtual void ProcessWork() = 0; 80 80 81 bool IsTermRequested ();82 83 81 public: 84 82 85 83 WorkerThread( ThreadPool *pThreadPool, const QString &sName ); 86 84 virtual ~WorkerThread(); 87 85 88 86 bool WaitForInitialized( unsigned long msecs ); 89 void RequestTerminate ();90 87 void SignalWork (); 91 88 void SetTimeout ( long nIdleTimeout ); 92 89 -
libs/libmythupnp/httpserver.cpp
239 239 240 240 pSocket->SocketDevice()->setBlocking( true ); 241 241 242 while( ! IsTermRequested()&& bKeepAlive && pSocket->IsValid())242 while( !m_bTermRequested && bKeepAlive && pSocket->IsValid()) 243 243 { 244 244 bTimeout = 0; 245 245 -
libs/libmythupnp/taskqueue.cpp
38 38 39 39 Task::Task() 40 40 { 41 m_mutex.lock();42 41 m_nTaskId = m_nTaskCount++; 43 m_mutex.unlock();44 42 } 45 43 46 44 ///////////////////////////////////////////////////////////////////////////// … … 74 72 75 73 TaskQueue::~TaskQueue() 76 74 { 77 Clear();78 }79 80 /////////////////////////////////////////////////////////////////////////////81 //82 /////////////////////////////////////////////////////////////////////////////83 84 bool TaskQueue::IsTermRequested()85 {86 m_mutex.lock();87 bool bTermRequested = m_bTermRequested;88 m_mutex.unlock();89 90 return( bTermRequested );91 }92 93 /////////////////////////////////////////////////////////////////////////////94 //95 /////////////////////////////////////////////////////////////////////////////96 97 void TaskQueue::RequestTerminate( )98 {99 m_mutex.lock();100 75 m_bTermRequested = true; 101 m_mutex.unlock();102 76 103 // Wait for thread to terminate.77 wait(); 104 78 105 wait( 1000);79 Clear(); 106 80 } 107 81 108 82 ///////////////////////////////////////////////////////////////////////////// … … 113 87 { 114 88 Task *pTask; 115 89 116 while ( ! IsTermRequested())90 while ( !m_bTermRequested ) 117 91 { 118 92 // ------------------------------------------------------------------ 119 93 // Process Any Tasks that may need to be executed. -
libs/libmythupnp/ssdp.cpp
67 67 { 68 68 DisableNotifications(); 69 69 70 m_bTermRequested = true; 71 72 wait(); 73 70 74 if (m_pNotifyTask != NULL) 71 75 m_pNotifyTask->Release(); 72 76 … … 83 87 // 84 88 ///////////////////////////////////////////////////////////////////////////// 85 89 86 bool SSDP::IsTermRequested()87 {88 m_lock.lock();89 bool bTermRequested = m_bTermRequested;90 m_lock.unlock();91 92 return( bTermRequested );93 }94 95 /////////////////////////////////////////////////////////////////////////////96 //97 /////////////////////////////////////////////////////////////////////////////98 99 void SSDP::RequestTerminate(void)100 {101 m_lock.lock();102 m_bTermRequested = true;103 m_lock.unlock();104 105 // Call wait to give thread time to terminate.106 107 wait( 500 );108 }109 110 /////////////////////////////////////////////////////////////////////////////111 //112 /////////////////////////////////////////////////////////////////////////////113 114 90 void SSDP::EnableNotifications() 115 91 { 116 92 if ( m_pNotifyTask == NULL ) … … 202 178 // Listen for new Requests 203 179 // ---------------------------------------------------------------------- 204 180 205 while (! IsTermRequested())181 while (!m_bTermRequested) 206 182 { 207 183 int nMaxSocket = 0; 208 184 -
libs/libmythupnp/upnp.cpp
165 165 166 166 if (g_pTaskQueue) 167 167 { 168 g_pTaskQueue->Clear();169 g_pTaskQueue->RequestTerminate();170 171 168 delete g_pTaskQueue; 172 169 g_pTaskQueue = NULL; 173 170 } 174 171 175 172 if (g_pSSDP) 176 173 { 177 VERBOSE(VB_UPNP, "UPnp::CleanUp() - disabling SSDP notifications");178 g_pSSDP->DisableNotifications();179 VERBOSE(VB_UPNP, "UPnp::CleanUp() - requesting SSDP terminate");180 g_pSSDP->RequestTerminate();181 182 174 delete g_pSSDP; 183 175 g_pSSDP = NULL; 184 176 VERBOSE(VB_UPNP, "UPnp::CleanUp() - deleted SSDP"); -
libs/libmythupnp/threadpool.cpp
129 129 130 130 WorkerThread::~WorkerThread() 131 131 { 132 } 132 m_bTermRequested = true; 133 133 134 ///////////////////////////////////////////////////////////////////////////// 135 // 136 ///////////////////////////////////////////////////////////////////////////// 134 m_WorkAvailable.SetEvent(); 137 135 138 bool WorkerThread::IsTermRequested() 139 { 140 m_mutex.lock(); 141 bool bTermRequested = m_bTermRequested; 142 m_mutex.unlock(); 143 144 return( bTermRequested ); 136 wait(); 145 137 } 146 138 147 139 ///////////////////////////////////////////////////////////////////////////// … … 164 156 // 165 157 ///////////////////////////////////////////////////////////////////////////// 166 158 167 void WorkerThread::RequestTerminate()168 {169 m_mutex.lock();170 m_bTermRequested = true;171 m_mutex.unlock();172 173 m_WorkAvailable.SetEvent();174 175 // Give time for thread to terminate.176 177 wait( 500 );178 }179 180 /////////////////////////////////////////////////////////////////////////////181 //182 /////////////////////////////////////////////////////////////////////////////183 184 159 void WorkerThread::SignalWork() 185 160 { 186 161 m_WorkAvailable.SetEvent(); … … 219 194 220 195 timer.start(); 221 196 222 while( ! IsTermRequested())197 while( !m_bTermRequested ) 223 198 { 224 199 if (m_bAllowTimeout && (timer.elapsed() > m_nIdleTimeoutMS) ) 225 200 break; … … 228 203 { 229 204 m_WorkAvailable.ResetEvent(); 230 205 231 if ( ! IsTermRequested())206 if ( !m_bTermRequested ) 232 207 { 233 208 try 234 209 { … … 307 282 308 283 if (pThread != NULL) 309 284 { 310 pThread->RequestTerminate();311 312 285 delete pThread; 313 286 } 314 287 -
libs/libmythupnp/taskqueue.h
73 73 { 74 74 protected: 75 75 76 TaskMap m_mapTasks;77 QMutex m_mutex;78 boolm_bTermRequested;76 TaskMap m_mapTasks; 77 QMutex m_mutex; 78 volatile bool m_bTermRequested; 79 79 80 80 protected: 81 81 82 bool IsTermRequested();83 84 82 virtual void run (); 85 83 86 84 public: … … 88 86 TaskQueue(); 89 87 virtual ~TaskQueue(); 90 88 91 void RequestTerminate ( );92 93 89 void Clear ( ); 94 90 void AddTask ( long msec , Task *pTask ); 95 91 void AddTask ( TaskTime tt, Task *pTask ); 96 92 void AddTask ( Task *pTask ); 97 93 98 94 Task *GetNextExpiredTask ( TaskTime tt, long nWithinMilliSecs = 50 ); 99 95 100 96 }; 101 97 102 98 #endif -
libs/libmythupnp/ssdp.h
68 68 69 69 UPnpNotifyTask *m_pNotifyTask; 70 70 71 boolm_bTermRequested;71 volatile bool m_bTermRequested; 72 72 QMutex m_lock; 73 73 74 74 protected: … … 79 79 bool ProcessSearchResponse( const QStringMap &sHeaders ); 80 80 bool ProcessNotify ( const QStringMap &sHeaders ); 81 81 82 bool IsTermRequested ();83 84 82 QString GetHeaderValue ( const QStringMap &headers, 85 83 const QString &sKey, 86 84 const QString &sDefault ); … … 96 94 97 95 virtual void run (); 98 96 99 void RequestTerminate(void);100 101 97 void EnableNotifications (); 102 98 void DisableNotifications(); 103 99