-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheventLoopThreadPool.hpp
More file actions
31 lines (30 loc) · 1.04 KB
/
Copy patheventLoopThreadPool.hpp
File metadata and controls
31 lines (30 loc) · 1.04 KB
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
#pragma once
#include "noncopyable.hpp"
#include <functional>
#include <memory>
#include <string>
#include <vector>
using namespace std;
class EventLoop;
class EventLoopThread;
class EventLoopThreadPool:Noncopyable
{
public:
using threadInitCallBack = function<void(EventLoop*)>; //创立eventloopthread需要的回调函数
EventLoopThreadPool(EventLoop* baseLoop, const string& nameArg);
~EventLoopThreadPool();
void setNumThread(int n){_numThreads = n;}
void start(const threadInitCallBack& cb = threadInitCallBack());
EventLoop* getNextLoop();
vector<EventLoop*> getAllLoops();
bool isStarted(){return _started;}
string name(){return _name;}
private:
EventLoop* _baseLoop; //使用moduo时候用户创立的loop;
string _name;
bool _started;
int _numThreads;
int _next; //分配channel是由baseLoop循环给subLoop分配,next是下一个待分配的subLoop序号
vector<unique_ptr<EventLoopThread> > _allThreads;
vector<EventLoop*> _allLoops; //线程开始运行时候会返回EventLoop的
};