Ticket #5481: 5481-v1.patch
File 5481-v1.patch, 4.0 KB (added by , 15 years ago) |
---|
-
programs/mythbackend/mainserver.cpp
112 112 class ProcessRequestThread : public QThread 113 113 { 114 114 public: 115 ProcessRequestThread(MainServer *ms) 116 : parent(ms), socket(0), threadlives(false) {}115 ProcessRequestThread(MainServer *ms) : 116 signalled(false), parent(ms), socket(NULL), threadlives(false) {} 117 117 118 118 void setup(MythSocket *sock) 119 119 { 120 120 lock.lock(); 121 121 socket = sock; 122 122 socket->UpRef(); 123 signalled = true; 123 124 waitCond.wakeOne(); 124 125 lock.unlock(); 125 126 } … … 128 129 { 129 130 lock.lock(); 130 131 threadlives = false; 132 signalled = true; 131 133 waitCond.wakeOne(); 132 134 lock.unlock(); 133 135 } 134 136 135 137 virtual void run() 136 138 { 139 lock.lock(); 137 140 threadlives = true; 141 lock.unlock(); 138 142 139 lock.lock();140 141 // Signal back to the thread that created this one in case it is142 // waiting to find out that it is up and running.143 waitCond.wakeOne();144 145 143 while (1) 146 144 { 147 waitCond.wait(&lock); 145 lock.lock(); 146 if (!signalled) 147 waitCond.wait(&lock); 148 signalled = false; 148 149 150 if (!socket) 151 { 152 lock.unlock(); 153 continue; 154 } 155 149 156 if (!threadlives) 157 { 158 socket->DownRef(); 159 socket = NULL; 160 lock.unlock(); 150 161 break; 162 } 151 163 152 if (!socket)153 continue;154 155 164 parent->ProcessRequest(socket); 156 165 socket->DownRef(); 157 166 socket = NULL; 158 167 parent->MarkUnused(this); 168 lock.unlock(); 159 169 } 160 161 lock.unlock();162 170 } 163 171 164 172 QMutex lock; 165 173 QWaitCondition waitCond; 174 bool signalled; 166 175 167 176 private: 168 177 MainServer *parent; … … 176 185 QMap<int, EncoderLink *> *tvList, 177 186 Scheduler *sched, AutoExpire *expirer) : 178 187 encoderList(tvList), mythserver(NULL), masterServerReconnect(NULL), 179 masterServer(NULL), ismaster(master), masterBackendOverride(false), 188 masterServer(NULL), ismaster(master), poolSignal(false), 189 masterBackendOverride(false), 180 190 m_sched(sched), m_expirer(expirer), deferredDeleteTimer(NULL), 181 191 autoexpireUpdateTimer(NULL), m_exitCode(BACKEND_EXIT_OK) 182 192 { … … 185 195 for (int i = 0; i < PRT_STARTUP_THREAD_COUNT; i++) 186 196 { 187 197 ProcessRequestThread *prt = new ProcessRequestThread(this); 188 prt->lock.lock();189 198 prt->start(); 190 prt->waitCond.wait(&prt->lock);191 prt->lock.unlock();192 199 threadPool.push_back(prt); 193 200 } 194 201 … … 266 273 if (threadPool.empty()) 267 274 { 268 275 VERBOSE(VB_IMPORTANT, "Waiting for a process request thread.."); 269 threadPoolCond.wait(&threadPoolLock, PRT_TIMEOUT); 276 if (!poolSignal) 277 threadPoolCond.wait(&threadPoolLock, PRT_TIMEOUT); 278 poolSignal = false; 270 279 } 271 280 if (!threadPool.empty()) 272 281 { … … 277 286 { 278 287 VERBOSE(VB_IMPORTANT, "Adding a new process request thread"); 279 288 prt = new ProcessRequestThread(this); 280 prt->lock.lock();281 289 prt->start(); 282 prt->waitCond.wait(&prt->lock);283 prt->lock.unlock();284 290 } 285 291 threadPoolLock.unlock(); 286 292 … … 655 661 { 656 662 threadPoolLock.lock(); 657 663 threadPool.push_back(prt); 664 poolSignal = true; 665 threadPoolCond.wakeOne(); 658 666 threadPoolLock.unlock(); 659 667 } 660 668 -
programs/mythbackend/mainserver.h
188 188 189 189 QMutex deletelock; 190 190 QMutex threadPoolLock; 191 bool poolSignal; 191 192 QWaitCondition threadPoolCond; 192 193 vector<ProcessRequestThread *> threadPool; 193 194