SpiecsEngine
 
Loading...
Searching...
No Matches

◆ Start() [2/2]

void Spices::Net::EventLoopThreadPool::Start ( int initThreadSize = 3,
ThreadInitCallback cb = nullptr )

Start Run this thread pool.

Parameters
[in]initThreadSizeThread Size.
[in]cbThreadInitCallback.

Wait for Thread EventLoop prepared.

Wait for Thread EventLoop prepared.

Definition at line 73 of file EventLoopThreadPool.cpp.

74 {
76
77 m_ThreadInitCallback = std::move(cb);
78 m_Loops.resize(initThreadSize);
79
80 m_IsPoolRunning = true;
81 m_InitThreadSize = initThreadSize;
82 m_IdleThreadSize = initThreadSize;
83 m_NThreads = initThreadSize;
84
85 for (uint32_t i = 0; i < m_InitThreadSize; i++)
86 {
87 auto ptr = std::make_unique<Thread<>>(std::bind(&EventLoopThreadPool::ThreadFunc, this, std::placeholders::_1), i);
88 int threadId = ptr->GetId();
89
90 m_Threads.emplace(threadId, std::move(ptr));
91 m_Threads[threadId]->Start();
92 }
93
97 m_IsThreadsPrepared.Wait(initThreadSize);
98
99 }
#define SPICES_PROFILE_ZONE
ThreadInitCallback m_ThreadInitCallback
ThreadInitCallback.
semaphore m_IsThreadsPrepared
ThreadsPrepared condition.
void ThreadFunc(Thread<> *thread)
Thread Function.
std::vector< EventLoop * > m_Loops
All threads EventLoop collection.
std::atomic_int m_IdleThreadSize
Idled thread size.
std::unordered_map< uint32_t, std::unique_ptr< Thread< Params... > > > m_Threads
Threads Container.
uint32_t m_InitThreadSize
Initialized thread size.
std::atomic_int m_NThreads
Threads Count.
std::atomic_bool m_IsPoolRunning
True if this thread pool is in use.
void Wait(int sign)
Wait this semaphore until it owns equal sign with given.
Definition Semaphore.h:57