made workers multithreaded

This commit is contained in:
Dominik Tomičević 2015-10-27 21:02:56 +01:00
parent b4d75c8317
commit 48841aabc0
3 changed files with 16 additions and 2 deletions

View File

@ -21,6 +21,12 @@ public:
thread = std::thread([this]() { loop(); });
}
Listener(Listener&& other)
{
this->thread = std::move(other.thread);
this->listener = std::move(other.listener);
}
~Listener()
{
alive.store(false, std::memory_order_release);

View File

@ -1,5 +1,5 @@
#include <iostream>
#include <array>
#include <vector>
#include "debug/log.hpp"
@ -33,7 +33,11 @@ make_socket_non_blocking (int sfd)
int main(void)
{
std::array<io::Worker, 8> workers;
std::vector<io::Worker> workers;
for(size_t i = 0; i < std::thread::hardware_concurrency(); ++i)
workers.emplace_back();
int idx = 0;
auto socket = io::Socket::create("7474");

View File

@ -16,6 +16,10 @@ class Worker : public Listener<Worker>
public:
Worker() = default;
Worker(Worker&& other)
{
}
bool accept(Socket& socket)
{
auto s = socket.accept(nullptr, nullptr);