MCPcopy Create free account
hub / github.com/F-Stack/f-stack / AllocThread

Method AllocThread

adapter/micro_thread/micro_thread.cpp:431–474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431MicroThread* 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
476void ThreadPool::FreeThread(MicroThread* thread)
477{

Callers 1

CreateThreadMethod · 0.80

Calls 3

HasFlagMethod · 0.80
UnsetFlagMethod · 0.80
InitialMethod · 0.80

Tested by

no test coverage detected