forked from lizhenghn123/CppLanguagePrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventLoopThreadPool.h
More file actions
60 lines (53 loc) · 1.73 KB
/
EventLoopThreadPool.h
File metadata and controls
60 lines (53 loc) · 1.73 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// ***********************************************************************
// Filename : EventLoopThreadPool.h
// Author : LIZHENG
// Created : 2014-11-07
// Description :
//
// Copyright (c) [email protected]. All rights reserved.
// ***********************************************************************
#ifndef ZL_EVENTLOOPTHREADPOOL_H
#define ZL_EVENTLOOPTHREADPOOL_H
#include "Define.h"
#include "base/NonCopy.h"
#include "net/SocketUtil.h"
#include "net/InetAddress.h"
#include "thread/Mutex.h"
namespace zl
{
namespace thread
{
class Thread;
class CountDownLatch;
}
}
NAMESPACE_ZL_NET_START
class EventLoop;
class EventLoopThreadPool : zl::NonCopy
{
public:
EventLoopThreadPool(EventLoop* baseLoop);
~EventLoopThreadPool();
std::vector<EventLoop*> getAllLoops() { return loops_; }
/// 设置EventLoopThreadPool的threads大小;if numThreads
/// < 0 : 设置该值为当前系统CPU并发数;
/// == 0 : 不使用EventLoopThreadPool,所有Channel都在同一个EventLoop中运行,默认值;
/// > 0 : 设置numThreads个线程,也即numThreads个EventLoop,每个连接选择其中一个
void setMultiReactorThreads(int numThreads);
void start();
bool isStart() { return started_; }
EventLoop* getNextLoop();
private:
void runLoop();
private:
EventLoop *baseLoop_;
bool started_;
int numThreads_;
size_t next_;
zl::thread::Mutex mutex_;
zl::thread::CountDownLatch *latch_;
std::vector<EventLoop*> loops_;
std::vector<zl::thread::Thread*> threads_;
};
NAMESPACE_ZL_NET_END
#endif /* EVENTLOOPTHREADPOOL */