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