1
This commit is contained in:
parent
9dc08638a0
commit
e41ffbd58f
@ -8,6 +8,9 @@ void IoMgr::Init()
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < IC_Max; ++i) {
|
for (int i = 0; i < IC_Max; ++i) {
|
||||||
io_contexts_.push_back(std::vector<std::shared_ptr<asio::io_context>>());
|
io_contexts_.push_back(std::vector<std::shared_ptr<asio::io_context>>());
|
||||||
|
auto& contexts = io_contexts_.at(i);
|
||||||
|
contexts.push_back(std::make_shared<asio::io_context>());
|
||||||
|
new std::thread(&IoMgr::WorkerThreadProc, this, contexts.at(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,12 +22,20 @@ void IoMgr::UnInit()
|
|||||||
std::shared_ptr<asio::io_context> IoMgr::GetIoContext(int type)
|
std::shared_ptr<asio::io_context> IoMgr::GetIoContext(int type)
|
||||||
{
|
{
|
||||||
if (type >= 0 && type < io_contexts_.size()) {
|
if (type >= 0 && type < io_contexts_.size()) {
|
||||||
auto& s = io_contexts_.at(type);
|
auto& contexts = io_contexts_.at(type);
|
||||||
if (s.empty()) {
|
if (contexts.empty()) {
|
||||||
return s.at(rand() % s.size());
|
return contexts.at(rand() % contexts.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IoMgr::WorkerThreadProc(std::shared_ptr<asio::io_context> io_context)
|
||||||
|
{
|
||||||
|
while (true) {
|
||||||
|
io_context->run();
|
||||||
|
io_context->reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,6 +17,9 @@ public:
|
|||||||
|
|
||||||
std::shared_ptr<asio::io_context> GetIoContext(int type);
|
std::shared_ptr<asio::io_context> GetIoContext(int type);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void WorkerThreadProc(std::shared_ptr<asio::io_context> io_context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<std::vector<std::shared_ptr<asio::io_context>>> io_contexts_;
|
std::vector<std::vector<std::shared_ptr<asio::io_context>>> io_contexts_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user