SpiecsEngine
 
Loading...
Searching...
No Matches
EventLoopThreadPool.h
Go to the documentation of this file.
1/**
2* @file EventLoopThreadPool.h.
3* @brief The EventLoopThreadPool Class Definitions.
4* @author Spices & Muduo.
5*/
6
7#pragma once
8#include "Core/Thread/ThreadPoolBasic.h"
9#include "EventLoop.h"
10#include "Core/Thread/Semaphore.h"
11
12namespace Spices {
13
14namespace Net {
15
16 /**
17 * @brief ThreadPool of Multiple threading EventLoop.
18 */
20 {
21 public:
22
23 using ThreadInitCallback = std::function<void(EventLoop*)>;
24
25 public:
26
27 /**
28 * @brief Constructor Function.
29 * Create Specific ThreadPool.
30 * @param[in] listenAddress InetAddress.
31 */
32 EventLoopThreadPool(const InetAddress& listenAddress)
34 , m_Next(0)
36 , m_ThreadInitCallback(nullptr)
37 {}
38
39 /**
40 * @brief Destructor Function.
41 */
42 virtual ~EventLoopThreadPool() override = default;
43
44 /**
45 * @brief Get next thread EventLoop.
46 * @return Returns Next Thread EventLoop.
47 */
49
50 /**
51 * @brief Get all thread EventLoop.
52 * @return Returns all thread EventLoop.
53 */
55
56 /**
57 * @brief Get ThreadPool Name.
58 * @return Returns ThreadPool Name.
59 */
60 const std::string& Name() const { return m_PoolName; }
61
62 /**
63 * @brief Thread Function.
64 * @param[in] thread Thread Entity.
65 */
66 void ThreadFunc(Thread<>* thread);
67
68 /**
69 * @brief Start Run this thread pool.
70 * @param[in] initThreadSize Thread Size.
71 * @param[in] cb ThreadInitCallback.
72 */
73 void Start(int initThreadSize = 3, ThreadInitCallback cb = nullptr);
74
75 private:
76
77 /**
78 * @brief Next EventLoop index.
79 */
80 int m_Next;
81
82 /**
83 * @brief ListenAddress.
84 */
86
87 /**
88 * @brief All threads EventLoop collection.
89 */
91
92 /**
93 * @brief ThreadInitCallback.
94 */
95 ThreadInitCallback m_ThreadInitCallback;
96
97 /**
98 * @brief ThreadsPrepared condition.
99 */
101
102 };
103
104}
105
106}
#define SPICES_PROFILE_ZONE
ThreadInitCallback m_ThreadInitCallback
ThreadInitCallback.
EventLoop * GetNextLoop()
Get next thread EventLoop.
InetAddress m_ListenAddress
ListenAddress.
std::vector< EventLoop * > GetAllLoops()
Get all thread EventLoop.
semaphore m_IsThreadsPrepared
ThreadsPrepared condition.
void ThreadFunc(Thread<> *thread)
Thread Function.
EventLoopThreadPool(const InetAddress &listenAddress)
Constructor Function. Create Specific ThreadPool.
void Start(int initThreadSize=3, ThreadInitCallback cb=nullptr)
Start Run this thread pool.
std::vector< EventLoop * > m_Loops
All threads EventLoop collection.
const std::string & Name() const
Get ThreadPool Name.
virtual ~EventLoopThreadPool() override=default
Destructor Function.
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.
Definition EventLoop.h:180
void Loop()
Start Event Loop.
Definition EventLoop.cpp:48
Wrapper of Poller and wakeup socket to acceptor(SubLoop).
Definition EventLoop.h:28
This class is Wrapper of current socket address.
Definition InetAddress.h:22
static bool SetThreadName(const std::string &name)
Set Thread name.
Thread Static Function Library.
Thread Function Object.
std::semaphore Implementation.
Definition Semaphore.h:16