| 294 | } |
| 295 | |
| 296 | WorkerThread* Coordinator::getThread() |
| 297 | { |
| 298 | MutexLockGuard guard(m_mutex, FB_FUNCTION); |
| 299 | WorkerThread* thd = NULL; |
| 300 | |
| 301 | if (!m_idleThreads.isEmpty()) |
| 302 | thd = m_idleThreads.pop(); |
| 303 | else |
| 304 | { |
| 305 | thd = WorkerThread::start(this); |
| 306 | if (thd) |
| 307 | thd->waitForState(WorkerThread::IDLE, -1); |
| 308 | } |
| 309 | |
| 310 | if (thd) |
| 311 | { |
| 312 | fb_assert(thd->getState() == WorkerThread::IDLE); |
| 313 | m_activeThreads.push(thd); |
| 314 | } |
| 315 | return thd; |
| 316 | } |
| 317 | |
| 318 | void Coordinator::releaseThread(WorkerThread* thd) |
| 319 | { |