2
3
4
5
22 loop = m_Loops[m_Next];
25 if (m_Next >= m_Loops.size())
40 return std::vector<EventLoop*>(1, EventLoopThreadWrapper::GetInst());
53
54
56 ss << m_PoolName << thread->GetId();
60 EventLoop* loop = EventLoopThreadWrapper::GetInst(&m_ListenAddress);
62 if (m_ThreadInitCallback)
64 m_ThreadInitCallback(loop);
67 m_Loops[thread->GetId()] = loop;
68 m_IsThreadsPrepared.Increase();
77 m_ThreadInitCallback = std::move(cb);
78 m_Loops.resize(initThreadSize);
80 m_IsPoolRunning =
true;
81 m_InitThreadSize = initThreadSize;
82 m_IdleThreadSize = initThreadSize;
83 m_NThreads = initThreadSize;
85 for (uint32_t i = 0; i < m_InitThreadSize; i++)
87 auto ptr = std::make_unique<Thread<>>(std::bind(&EventLoopThreadPool::ThreadFunc,
this, std::placeholders::_1), i);
88 int threadId = ptr->GetId();
90 m_Threads.emplace(threadId, std::move(ptr));
91 m_Threads[threadId]->Start();
95
96
97 m_IsThreadsPrepared.Wait(initThreadSize);
#define SPICES_PROFILE_ZONE
EventLoop * GetNextLoop()
Get next thread EventLoop.
std::vector< EventLoop * > GetAllLoops()
Get all thread EventLoop.
int m_Next
Next EventLoop index.
void ThreadFunc(Thread<> *thread)
Thread Function.
void Start(int initThreadSize=3, ThreadInitCallback cb=nullptr)
Start Run this thread pool.
ThreadPool of Multiple threading EventLoop.
static EventLoop *& GetInst(InetAddress *address=nullptr)
Get EventLoop Instance. @reutrn Returns EventLoop Instance.
Wrapper of Instance/Delete ThreadCache in thread.
void Loop()
Start Event Loop.
Wrapper of Poller and wakeup socket to acceptor(SubLoop).
static bool SetThreadName(const std::string &name)
Set Thread name.
Thread Static Function Library.