| 367 | //-------------------------------------------------------------------------- |
| 368 | |
| 369 | void ThreadPool::shutdown() |
| 370 | { |
| 371 | const U32 numThreads = mNumThreads; |
| 372 | |
| 373 | // Tell our worker threads to stop. |
| 374 | |
| 375 | for( WorkerThread* thread = mThreads; thread != 0; thread = thread->getNext() ) |
| 376 | thread->stop(); |
| 377 | |
| 378 | // Release the semaphore as many times as there are threads. |
| 379 | // Doing this separately guarantees we're not waking a thread |
| 380 | // that hasn't been set its stop flag yet. |
| 381 | |
| 382 | for( U32 n = 0; n < numThreads; ++ n ) |
| 383 | mSemaphore.release(); |
| 384 | |
| 385 | // Delete each worker thread. Wait until death as we're prone to |
| 386 | // running into issues with decomposing work item lists otherwise. |
| 387 | |
| 388 | for( WorkerThread* thread = mThreads; thread != 0; ) |
| 389 | { |
| 390 | WorkerThread* next = thread->getNext(); |
| 391 | thread->join(); |
| 392 | delete thread; |
| 393 | thread = next; |
| 394 | } |
| 395 | |
| 396 | mThreads = NULL; |
| 397 | mNumThreads = 0; |
| 398 | } |
| 399 | |
| 400 | //-------------------------------------------------------------------------- |
| 401 | |