| 429 | } |
| 430 | |
| 431 | MicroThread* ThreadPool::AllocThread() |
| 432 | { |
| 433 | MT_ATTR_API_SET(492069, _total_num); |
| 434 | |
| 435 | MicroThread* thread = NULL; |
| 436 | if (!_freelist.empty()) |
| 437 | { |
| 438 | thread = _freelist.front(); |
| 439 | _freelist.pop(); |
| 440 | |
| 441 | ASSERT(thread->HasFlag(MicroThread::FREE_LIST)); |
| 442 | |
| 443 | thread->UnsetFlag(MicroThread::FREE_LIST); |
| 444 | _use_num++; |
| 445 | return thread; |
| 446 | } |
| 447 | |
| 448 | MT_ATTR_API(320846, 1); // pool no nore |
| 449 | if (_total_num >= _max_num) |
| 450 | { |
| 451 | MT_ATTR_API(361140, 1); // no more quota |
| 452 | MTLOG_ERROR("total %d is outof max: %d", _total_num,_max_num); |
| 453 | return NULL; |
| 454 | } |
| 455 | |
| 456 | thread = new MicroThread(); |
| 457 | if ((NULL == thread) || (false == thread->Initial())) |
| 458 | { |
| 459 | MT_ATTR_API(320847, 1); // pool init fail |
| 460 | MTLOG_ERROR("thread alloc failed, thread: %p", thread); |
| 461 | if (thread) delete thread; |
| 462 | return NULL; |
| 463 | } |
| 464 | _total_num++; |
| 465 | _use_num++; |
| 466 | if(_use_num >(int) default_thread_num){ |
| 467 | if(((int) default_thread_num * 2 )< _max_num){ |
| 468 | last_default_thread_num = default_thread_num; |
| 469 | default_thread_num = default_thread_num * 2; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | return thread; |
| 474 | } |
| 475 | |
| 476 | void ThreadPool::FreeThread(MicroThread* thread) |
| 477 | { |
no test coverage detected