| 307 | //-------------------------------------------------------------------------- |
| 308 | |
| 309 | ThreadPool::ThreadPool( const char* name, U32 numThreads ) |
| 310 | : mName( name ), |
| 311 | mNumThreads( numThreads ), |
| 312 | mNumThreadsAwake( 0 ), |
| 313 | mNumPendingItems( 0 ), |
| 314 | mSemaphore( 0 ), |
| 315 | mThreads( 0 ) |
| 316 | { |
| 317 | // Number of worker threads to create. |
| 318 | |
| 319 | if( !mNumThreads ) |
| 320 | { |
| 321 | // Use platformCPUInfo directly as in the case of the global pool, |
| 322 | // Platform::SystemInfo will not yet have been initialized. |
| 323 | |
| 324 | U32 numLogical = 0; |
| 325 | U32 numCores = 0; |
| 326 | |
| 327 | CPUInfo::CPUCount( numLogical, numCores ); |
| 328 | |
| 329 | const U32 baseCount = getMax( numLogical, numCores ); |
| 330 | mNumThreads = (baseCount > 0) ? baseCount : 2; |
| 331 | } |
| 332 | |
| 333 | #ifdef DEBUG_SPEW |
| 334 | Platform::outputDebugString( "[ThreadPool] spawning %i threads", mNumThreads ); |
| 335 | #endif |
| 336 | |
| 337 | // Create the threads. |
| 338 | |
| 339 | mNumThreadsAwake = mNumThreads; |
| 340 | mNumThreadsReady = mNumThreads; |
| 341 | for( U32 i = 0; i < mNumThreads; i ++ ) |
| 342 | { |
| 343 | WorkerThread* thread = new WorkerThread( this, i ); |
| 344 | thread->start(); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | //-------------------------------------------------------------------------- |
| 349 | |