Changeset 48911 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Oct 7, 2013 12:01:17 AM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/globals
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.cpp
r48910 r48911 30 30 #include <VBox/sup.h> 31 31 32 /** @todo r=bird: this code was racy, inefficient and buggy in it's first33 * incarnation. What is required from RTReqPool for it to replace the34 * internals here? COM init/term hooks, sure. Does the threads need to35 * be QThreads? */36 37 38 32 /** 39 33 * COM capable worker thread for the UIThreadPool. … … 55 49 int getIndex() const { return m_iIndex; } 56 50 57 /** Disables sigFinished. 51 /** Disables sigFinished. For optimizing pool termination. */ 58 52 void setNoFinishedSignal() 59 53 { … … 76 70 77 71 78 UIThreadPool::UIThreadPool(ulong cMaxWorkers /* = 3*/, ulong cMsWorkerIdleTimeout /* = 5000*/)72 UIThreadPool::UIThreadPool(ulong cMaxWorkers /* = 3 */, ulong cMsWorkerIdleTimeout /* = 5000 */) 79 73 : m_workers(cMaxWorkers) 80 74 , m_cMsIdleTimeout(cMsWorkerIdleTimeout) … … 82 76 , m_cIdleWorkers(0) 83 77 , m_fTerminating(false) /* termination status */ 84 , m_everythingLocker(QMutex::NonRecursive)85 78 { 86 79 } … … 91 84 setTerminating(); 92 85 86 m_everythingLocker.lock(); /* paranoia */ 87 93 88 /* Cleanup all the workers: */ 94 m_everythingLocker.lock(); /* paranoia */95 89 for (int idxWorker = 0; idxWorker < m_workers.size(); ++idxWorker) 96 90 { … … 134 128 else if (m_cWorkers < m_workers.size()) 135 129 { 136 /* Find free slot .*/130 /* Find free slot: */ 137 131 int idxFirstUnused = m_workers.size(); 138 132 while (idxFirstUnused-- > 0) … … 165 159 { 166 160 /* Acquire termination-flag: */ 167 QMutexLocker lock(&m_everythingLocker);161 m_everythingLocker.lock(); 168 162 bool fTerminating = m_fTerminating; 169 lock.unlock();163 m_everythingLocker.unlock(); 170 164 171 165 return fTerminating; … … 195 189 UITask* UIThreadPool::dequeueTask(UIThreadWorker *pWorker) 196 190 { 197 /* 198 * Dequeue a task, watching out for terminations. For opimal efficiency in 199 * enqueueTask() we keep count of idle threads. 200 * 201 * If the wait times out, we'll return NULL and terminate the thread. 202 */ 191 /* Dequeue a task, watching out for terminations. 192 * For opimal efficiency in enqueueTask() we keep count of idle threads. 193 * If the wait times out, we'll return NULL and terminate the thread. */ 203 194 m_everythingLocker.lock(); 204 195 … … 219 210 } 220 211 221 /* If we timed out already, then quit the worker thread. 212 /* If we timed out already, then quit the worker thread. To prevent a 222 213 race between enqueueTask and the queue removal of the thread from 223 the workers vector, we remove it here already. 214 the workers vector, we remove it here already. (This does not apply 224 215 to the termination scenario.) */ 225 216 if (fIdleTimedOut) … … 254 245 { 255 246 /* Wait for the thread to finish completely, then delete the thread 256 object. 247 object. We have already removed the thread from the workers vector. 257 248 Note! We don't want to use 'this' here, in case it's invalid. */ 258 249 pWorker->wait(); … … 289 280 void UIThreadWorker::run() 290 281 { 291 // LogRelFlow(("UIThreadWorker #%d: Started...\n", m_iIndex));292 293 282 /* Initialize COM: */ 294 283 COMBase::InitializeCOM(false); … … 297 286 while (UITask *pTask = m_pPool->dequeueTask(this)) 298 287 { 299 /* Process t ask: */300 // LogRelFlow(("UIThreadWorker #%d: Task acquired...\n", m_iIndex)); 288 /* Process the task if we are not terminating. 289 * Please take into account tasks are cleared by their creator. */ 301 290 if (!m_pPool->isTerminating()) 302 291 pTask->start(); 303 /** @todo else: Just leak the task? */304 // LogRelFlow(("UIThreadWorker #%d: Task processed!\n", m_iIndex));305 292 } 306 293 … … 312 299 if (!m_fNoFinishedSignal) 313 300 emit sigFinished(this); 314 315 // LogRelFlow(("UIThreadWorker #%d: Finished!\n", m_iIndex));316 301 } 317 302 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h
r48908 r48911 57 57 58 58 /* Protected API: Worker-thread stuff: */ 59 UITask *dequeueTask(UIThreadWorker *pWorker);59 UITask* dequeueTask(UIThreadWorker *pWorker); 60 60 61 61 private slots: … … 68 68 69 69 private: 70 70 71 /** @name Worker thread related variables. 71 72 * @{ */
Note:
See TracChangeset
for help on using the changeset viewer.