made workers multithreaded
This commit is contained in:
parent
b4d75c8317
commit
48841aabc0
@ -21,6 +21,12 @@ public:
|
|||||||
thread = std::thread([this]() { loop(); });
|
thread = std::thread([this]() { loop(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Listener(Listener&& other)
|
||||||
|
{
|
||||||
|
this->thread = std::move(other.thread);
|
||||||
|
this->listener = std::move(other.listener);
|
||||||
|
}
|
||||||
|
|
||||||
~Listener()
|
~Listener()
|
||||||
{
|
{
|
||||||
alive.store(false, std::memory_order_release);
|
alive.store(false, std::memory_order_release);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <array>
|
#include <vector>
|
||||||
|
|
||||||
#include "debug/log.hpp"
|
#include "debug/log.hpp"
|
||||||
|
|
||||||
@ -33,7 +33,11 @@ make_socket_non_blocking (int sfd)
|
|||||||
|
|
||||||
int main(void)
|
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;
|
int idx = 0;
|
||||||
|
|
||||||
auto socket = io::Socket::create("7474");
|
auto socket = io::Socket::create("7474");
|
||||||
|
@ -16,6 +16,10 @@ class Worker : public Listener<Worker>
|
|||||||
public:
|
public:
|
||||||
Worker() = default;
|
Worker() = default;
|
||||||
|
|
||||||
|
Worker(Worker&& other)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool accept(Socket& socket)
|
bool accept(Socket& socket)
|
||||||
{
|
{
|
||||||
auto s = socket.accept(nullptr, nullptr);
|
auto s = socket.accept(nullptr, nullptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user