| 474 | } |
| 475 | |
| 476 | void ThreadPool::FreeThread(MicroThread* thread) |
| 477 | { |
| 478 | ASSERT(!thread->HasFlag(MicroThread::FREE_LIST)); |
| 479 | thread->Reset(); |
| 480 | _use_num--; |
| 481 | _freelist.push(thread); |
| 482 | thread->SetFlag(MicroThread::FREE_LIST); |
| 483 | |
| 484 | unsigned int free_num = _freelist.size(); |
| 485 | if ((free_num > default_thread_num) && (free_num > 1)) |
| 486 | { |
| 487 | thread = _freelist.front(); |
| 488 | _freelist.pop(); |
| 489 | thread->Destroy(); |
| 490 | delete thread; |
| 491 | _total_num--; |
| 492 | if(default_thread_num / 2 >= DEFAULT_THREAD_NUM){ |
| 493 | last_default_thread_num = default_thread_num; |
| 494 | default_thread_num = default_thread_num / 2; |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | int ThreadPool::GetUsedNum(void) |
| 500 | { |
no test coverage detected