trantor
Non-blocking I/O cross-platform TCP network library, using C++14
Loading...
Searching...
No Matches
EventLoopThreadPool.h
Go to the documentation of this file.
1
14
15#pragma once
16
18#include <trantor/exports.h>
19#include <vector>
20#include <memory>
21#include <atomic>
22
23namespace trantor
24{
29class TRANTOR_EXPORT EventLoopThreadPool : NonCopyable
30{
31 public:
32 EventLoopThreadPool() = delete;
33
40 EventLoopThreadPool(size_t threadNum,
41 const std::string &name = "EventLoopThreadPool");
42
47 void start();
48
54 void wait();
55
61 size_t size()
62 {
63 return loopThreadVector_.size();
64 }
65
72
80 EventLoop *getLoop(size_t id);
81
87 std::vector<EventLoop *> getLoops() const;
88
89 private:
90 std::vector<std::shared_ptr<EventLoopThread>> loopThreadVector_;
91 std::atomic<size_t> loopIndex_{0};
92};
93} // namespace trantor
EventLoop * getNextLoop()
Get the next event loop in the pool.
EventLoop * getLoop(size_t id)
Get the event loop in the id position in the pool.
void wait()
Wait for all event loops in the pool to quit.
void start()
Run all event loops in the pool.
std::vector< EventLoop * > getLoops() const
Get all event loops in the pool.
EventLoopThreadPool(size_t threadNum, const std::string &name="EventLoopThreadPool")
Construct a new event loop thread pool instance.
size_t size()
Return the number of the event loop.
Definition EventLoopThreadPool.h:61
As the name implies, this class represents an event loop that runs in a particular thread....
Definition EventLoop.h:56
Definition EventLoop.h:34