SpiecsEngine
 
Loading...
Searching...
No Matches
Spices::Net::EventLoopThreadPool Class Reference

ThreadPool of Multiple threading EventLoop. More...

#include <EventLoopThreadPool.h>

Inheritance diagram for Spices::Net::EventLoopThreadPool:
Spices::ThreadPool_Basic< Params >

Public Types

using ThreadInitCallback = std::function<void(EventLoop*)>
 
using Task = std::function<void(Params...)>
 Thread Function lambda Object.
 

Public Member Functions

 EventLoopThreadPool (const InetAddress &listenAddress)
 Constructor Function. Create Specific ThreadPool.
 
virtual ~EventLoopThreadPool () override=default
 Destructor Function.
 
EventLoopGetNextLoop ()
 Get next thread EventLoop.
 
std::vector< EventLoop * > GetAllLoops ()
 Get all thread EventLoop.
 
const std::string & Name () const
 Get ThreadPool Name.
 
void ThreadFunc (Thread<> *thread)
 Thread Function.
 
void Start (int initThreadSize=3, ThreadInitCallback cb=nullptr)
 Start Run this thread pool.
 
void SetMode (PoolMode mode)
 Set Pool Run Mode.
 
void SetThreadIdleTimeOut (int idleTime)
 Set Pool Threads idle time out.
 
void Wait ()
 Wait for all tasks executed finish in taskqueue.
 
void Continue ()
 Continue ThreadPool.
 
void Suspend ()
 Suspend ThreadPool.
 
void SubmitThreadTask_LightWeight (uint32_t threadId, std::function< void(Params...)> func)
 Submit a task to specific thread.
 
void SubmitThreadTask_LightWeight_ForEach (std::function< void(Params...)> func)
 Submit a task to all thread.
 
template<typename Func , typename... Args>
auto SubmitPoolTask (Func &&func, Args &&... args) -> std::future< decltype(func(std::forward< Args >(args)...))>
 Submit a task to task queue, and wait for a idle thread to execute it.
 
void Start (int initThreadSize=0.5 *std::thread::hardware_concurrency())
 Start Run this thread pool.
 
const int GetThreadsCount () const
 Get Threads Count. This function is just used for unit test, should not be used in engine.
 
const std::unordered_map< uint32_t, std::unique_ptr< Thread< Params... > > > & GetThreads () const
 Get Threads. This function is just used for unit test, should not be used in engine.
 
const int GetInitThreadSize () const
 GetInitThreadSize. This function is just used for unit test, should not be used in engine.
 
const int GetIdleThreadSize () const
 GetIdleThreadSize. This function is just used for unit test, should not be used in engine.
 
const int GetTasks () const
 Get TaskQueue Count. This function is just used for unit test, should not be used in engine.
 
const PoolModeGetPoolMode () const
 GetPoolMode. This function is just used for unit test, should not be used in engine.
 
const int GetThreadIdleTimeOut () const
 ThreadIdleTimeOut. This function is just used for unit test, should not be used in engine.
 
const bool IsPoolRunning () const
 GetIsPoolRunning. This function is just used for unit test, should not be used in engine.
 

Protected Member Functions

bool CheckRunningState () const
 Check whether this pool is still in running.
 

Protected Attributes

std::string m_PoolName
 This ThreadPool Name.
 
std::unordered_map< uint32_t, std::unique_ptr< Thread< Params... > > > m_Threads
 Threads Container.
 
std::atomic_int m_NThreads
 Threads Count.
 
uint32_t m_InitThreadSize
 Initialized thread size.
 
uint32_t m_ThreadIdleTimeOut
 thread idle time out.
 
std::atomic_int m_IdleThreadSize
 Idled thread size.
 
std::queue< Taskm_TaskQueue
 Task Queue.
 
std::atomic_int m_Tasks
 Number of tasks;.
 
std::mutex m_Mutex
 Mutex for thread safe.
 
std::condition_variable m_NotEmpty
 Task Queue not empty.
 
std::condition_variable m_ExitCond
 Thread pool Exit Condition.
 
std::condition_variable m_IdleCond
 Thread pool thread idle Condition.
 
PoolMode m_PoolMode
 Thread Pool Run Mode.
 
std::atomic_bool m_IsPoolRunning
 True if this thread pool is in use.
 
bool m_IsSuspend
 True if needs suspend on executing the task.
 

Private Attributes

int m_Next
 Next EventLoop index.
 
InetAddress m_ListenAddress
 ListenAddress.
 
std::vector< EventLoop * > m_Loops
 All threads EventLoop collection.
 
ThreadInitCallback m_ThreadInitCallback
 ThreadInitCallback.
 
semaphore m_IsThreadsPrepared
 ThreadsPrepared condition.
 

Detailed Description

ThreadPool of Multiple threading EventLoop.

Definition at line 19 of file EventLoopThreadPool.h.


The documentation for this class was generated from the following files: