| 388 | //-------------------------------------------------------------------------- |
| 389 | |
| 390 | void ThreadPool::queueWorkItem( WorkItem* item ) |
| 391 | { |
| 392 | bool executeRightAway = ( getForceAllMainThread() ); |
| 393 | #ifdef DEBUG_SPEW |
| 394 | Platform::outputDebugString( "[ThreadPool] %s work item '0x%x'", |
| 395 | ( executeRightAway ? "executing" : "queuing" ), |
| 396 | item ); |
| 397 | #endif |
| 398 | |
| 399 | if( executeRightAway ) |
| 400 | item->process(); |
| 401 | else |
| 402 | { |
| 403 | // Put the item in the queue. |
| 404 | dFetchAndAdd( mNumPendingItems, 1 ); |
| 405 | mWorkItemQueue.insert( item->getPriority(), item ); |
| 406 | |
| 407 | mSemaphore.release(); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | //-------------------------------------------------------------------------- |
| 412 | |