remove boost::thread from Server

This commit is contained in:
Dennis Luxen 2014-05-13 10:02:36 +02:00
parent 37dd05a9b5
commit 1816e6607e

View File

@ -33,10 +33,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <thread>
#include <vector> #include <vector>
class Server class Server
@ -59,20 +59,23 @@ class Server
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error)); boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));
} }
Server() = delete;
Server(const Server &) = delete; Server(const Server &) = delete;
void Run() void Run()
{ {
std::vector<std::shared_ptr<boost::thread>> threads; std::vector<std::shared_ptr<std::thread>> threads;
for (unsigned i = 0; i < thread_pool_size; ++i) for (unsigned i = 0; i < thread_pool_size; ++i)
{ {
std::shared_ptr<boost::thread> thread = std::make_shared<boost::thread>( std::shared_ptr<std::thread> thread = std::make_shared<std::thread>(
boost::bind(&boost::asio::io_service::run, &io_service)); boost::bind(&boost::asio::io_service::run, &io_service));
threads.push_back(thread); threads.push_back(thread);
} }
for (unsigned i = 0; i < threads.size(); ++i) for (unsigned i = 0; i < threads.size(); ++i)
{
threads[i]->join(); threads[i]->join();
} }
}
void Stop() { io_service.stop(); } void Stop() { io_service.stop(); }