-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathepoller_thread_pool.cpp
More file actions
81 lines (64 loc) · 1.31 KB
/
Copy pathepoller_thread_pool.cpp
File metadata and controls
81 lines (64 loc) · 1.31 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <boost/bind.hpp>
#include <stdio.h>
#include "epoller.h"
#include "epoller_thread.h"
#include "epoller_thread_pool.h"
using namespace ydx;
EPollerThreadPool::EPollerThreadPool(EPollPoller * epoll_base, const std::string & nameArg)
:epoll_base_(epoll_base),
name_(nameArg),
started_(false),
numThreads_(0),
next_(0)
{}
EPollerThreadPool::~EPollerThreadPool()
{}
void EPollerThreadPool::start()
{
started_ = true;
for (int i = 0; i < numThreads_ ; ++i)
{
char buf[name_.size() + 32];
snprintf(buf, sizeof buf, "%s%d", name_.c_str(), i);
EPollerThread* t = new EPollerThread(name_);
threads_.push_back(t);
epolls_.push_back(t->startEpoll());
}
if( numThreads_ == 0)
{
}
}
EPollPoller* EPollerThreadPool::getNextLoop()
{
EPollPoller *epoll = epoll_base_;
if(!epolls_.empty())
{
epoll = epolls_[next_];
++next_;
if (implicit_cast<size_t>(next_) >= epolls_.size())
{
next_ = 0;
}
}
return epoll;
}
EPollPoller* EPollerThreadPool::getLoopForHash(size_t hashCode)
{
EPollPoller* epoll = epoll_base_;
if (!epolls_.empty())
{
epoll = epolls_[hashCode % epolls_.size()];
}
return epoll;
}
std::vector<EPollPoller*> EPollerThreadPool::getAllLoops()
{
if (epolls_.empty())
{
return std::vector<EPollPoller*>(1, epoll_base_);
}
else
{
return epolls_;
}
}