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