-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventLoopThreadPool.h
More file actions
40 lines (30 loc) · 1019 Bytes
/
EventLoopThreadPool.h
File metadata and controls
40 lines (30 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <functional>
#include <string>
#include <vector>
#include <memory>
#include "noncopyable.h"
class EventLoop;
class EventLoopThread;
class EventLoopThreadPool : noncopyable
{
public:
using ThreadInitCallback = std::function<void(EventLoop*)>;
EventLoopThreadPool(EventLoop *baseLoop,const std::string &name);
~EventLoopThreadPool();
void setThreadNum(int numberThreads){numThreads_ = numberThreads;}
void start(const ThreadInitCallback &cb = ThreadInitCallback());
// 如果 工作在多线程中 baseLoop 可以通过轮询的方式 分配subloop
EventLoop* getNextloop();
std::vector<EventLoop*> getAllLoops();
bool started() const {return started_;}
const std::string name() const {return name_;}
private:
EventLoop* baseLoop_; // EventLoop loop; 一个线程
std::string name_;
bool started_;
int numThreads_;
int next_;
std::vector<std::unique_ptr<EventLoopThread>> thread_;
std::vector<EventLoop*> loops_;
};