| 385 | unsigned int ThreadPool::default_stack_size = DEFAULT_STACK_SIZE; ///< 128k stack. |
| 386 | |
| 387 | bool ThreadPool::InitialPool(int max_num) |
| 388 | { |
| 389 | MicroThread *thread = NULL; |
| 390 | for (unsigned int i = 0; i < default_thread_num; i++) |
| 391 | { |
| 392 | thread = new MicroThread(); |
| 393 | if ((NULL == thread) || (false == thread->Initial())) |
| 394 | { |
| 395 | MTLOG_ERROR("init pool, thread %p init failed", thread); |
| 396 | if (thread) delete thread; |
| 397 | continue; |
| 398 | } |
| 399 | thread->SetFlag(MicroThread::FREE_LIST); |
| 400 | _freelist.push(thread); |
| 401 | } |
| 402 | |
| 403 | _total_num = _freelist.size(); |
| 404 | _max_num = max_num; |
| 405 | _use_num = 0; |
| 406 | if (_total_num <= 0) |
| 407 | { |
| 408 | return false; |
| 409 | } |
| 410 | else |
| 411 | { |
| 412 | return true; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | void ThreadPool::DestroyPool() |
| 417 | { |