COROIO: coroio/loop_pool.hpp Source File
COROIO
Loading...
Searching...
No Matches
loop_pool.hpp
1#pragma once
2
3#ifndef _WIN32
4
5#include "loop_thread.hpp"
6
7namespace NNet {
8
9template<typename TPoller>
10class TLoopPool {
11public:
12 TLoopPool(int nthreads)
13 : Threads_(nthreads)
14 {
15 for (auto& thread : Threads_) {
16 thread = std::make_unique<TLoopThread<TPoller>>();
17 }
18 }
19
20 TLoopPool() = delete;
21 TLoopPool(const TLoopPool&) = delete;
22
23 void Start() {
24 for (auto& thread : Threads_) {
25 thread->Start();
26 }
27 }
28
29 void Submit(TFuture<void, TLazyDetachedPolicy>&& task) {
30 Threads_[NextThread_]->Submit(std::move(task));
31 NextThread_ = (NextThread_ + 1) % Threads_.size();
32 }
33
34private:
35 std::vector<std::unique_ptr<TLoopThread<TPoller>>> Threads_;
36 size_t NextThread_ = 0;
37};
38
39} // namespace NNet
40
41#endif // _WIN32
Definition corochain.hpp:74