-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioservicepool.cpp
More file actions
43 lines (34 loc) · 834 Bytes
/
Copy pathioservicepool.cpp
File metadata and controls
43 lines (34 loc) · 834 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
41
42
43
#include "ioservicepool.h"
#include <boost/asio.hpp>
IOServicePool::IOServicePool(boost::asio::io_service* IOService,
unsigned int NumberOfThreads) :
m_IOService(IOService),
m_NumberOfThreads(NumberOfThreads)
{
}
IOServicePool::~IOServicePool()
{
Stop();
}
void IOServicePool::Start()
{
m_Work = new boost::asio::io_service::work(*m_IOService);
for(unsigned int i = 0; i < m_NumberOfThreads; ++i)
{
m_ThreadPool.push_back(new std::thread(&IOServicePool::Run, this));
}
}
void IOServicePool::Stop()
{
if(m_Work) { delete m_Work; }
for(std::thread* Thread : m_ThreadPool)
{
Thread->join();
delete Thread;
}
m_ThreadPool.erase(m_ThreadPool.begin(), m_ThreadPool.end());
}
void IOServicePool::Run()
{
m_IOService->run();
}