Ticket #5481: conditional.patch
File conditional.patch, 3.6 KB (added by , 16 years ago) |
---|
-
programs/mythbackend/mainserver.h
182 182 183 183 QMutex deletelock; 184 184 QMutex threadPoolLock; 185 bool poolSignal; 185 186 QWaitCondition threadPoolCond; 186 187 vector<ProcessRequestThread *> threadPool; 187 188 -
programs/mythbackend/mainserver.cpp
107 107 class ProcessRequestThread : public QThread 108 108 { 109 109 public: 110 ProcessRequestThread(MainServer *ms) { parent = ms; } 110 ProcessRequestThread(MainServer *ms) { 111 parent = ms; 112 signalled = false; 113 socket = NULL; 114 } 111 115 112 116 void setup(MythSocket *sock) 113 117 { 114 118 lock.lock(); 115 119 socket = sock; 116 120 socket->UpRef(); 121 signalled = true; 117 122 waitCond.wakeOne(); 118 123 lock.unlock(); 119 124 } … … 122 127 { 123 128 lock.lock(); 124 129 threadlives = false; 130 signalled = true; 125 131 waitCond.wakeOne(); 126 132 lock.unlock(); 127 133 } 128 134 129 135 virtual void run() 130 136 { 137 lock.lock(); 131 138 threadlives = true; 139 lock.unlock(); 132 140 133 lock.lock();134 135 // Signal back to the thread that created this one in case it is136 // waiting to find out that it is up and running.137 waitCond.wakeOne();138 139 141 while (1) 140 142 { 143 lock.lock(); 144 if (signalled == false) { 141 145 waitCond.wait(&lock); 146 } 147 signalled = false; 142 148 143 if (!threadlives) 149 if (!socket) { 150 lock.unlock(); 151 continue; 152 } 153 154 if (!threadlives) { 155 socket->DownRef(); 156 socket = NULL; 157 lock.unlock(); 144 158 break; 159 } 145 160 146 if (!socket)147 continue;148 149 161 parent->ProcessRequest(socket); 150 162 socket->DownRef(); 151 163 socket = NULL; 152 164 parent->MarkUnused(this); 153 }154 155 165 lock.unlock(); 156 166 } 167 } 157 168 158 169 QMutex lock; 159 170 QWaitCondition waitCond; 171 bool signalled; 160 172 161 173 private: 162 174 MainServer *parent; … … 176 188 ismaster = master; 177 189 masterServer = NULL; 178 190 191 poolSignal = false; 192 179 193 encoderList = tvList; 180 194 AutoExpire::Update(true); 181 195 182 196 for (int i = 0; i < PRT_STARTUP_THREAD_COUNT; i++) 183 197 { 184 198 ProcessRequestThread *prt = new ProcessRequestThread(this); 185 prt->lock.lock();186 199 prt->start(); 187 prt->waitCond.wait(&prt->lock);188 prt->lock.unlock();189 200 threadPool.push_back(prt); 190 201 } 191 202 … … 260 271 if (threadPool.empty()) 261 272 { 262 273 VERBOSE(VB_IMPORTANT, "Waiting for a process request thread.."); 274 if (poolSignal == false) { 263 275 threadPoolCond.wait(&threadPoolLock, PRT_TIMEOUT); 264 276 } 277 poolSignal = false; 278 } 265 279 if (!threadPool.empty()) 266 280 { 267 281 prt = threadPool.back(); … … 271 285 { 272 286 VERBOSE(VB_IMPORTANT, "Adding a new process request thread"); 273 287 prt = new ProcessRequestThread(this); 274 prt->lock.lock();275 288 prt->start(); 276 prt->waitCond.wait(&prt->lock);277 prt->lock.unlock();278 289 } 279 290 threadPoolLock.unlock(); 280 291 … … 643 654 { 644 655 threadPoolLock.lock(); 645 656 threadPool.push_back(prt); 657 poolSignal = true; 658 threadPoolCond.wakeOne(); 646 659 threadPoolLock.unlock(); 647 660 } 648 661