1 | #pragma once |
---|---|
2 | |
3 | #include <mbgl/actor/scheduler.hpp> |
4 | |
5 | #include <condition_variable> |
6 | #include <mutex> |
7 | #include <queue> |
8 | #include <thread> |
9 | |
10 | namespace mbgl { |
11 | |
12 | class ThreadPool : public Scheduler { |
13 | public: |
14 | ThreadPool(std::size_t count); |
15 | ~ThreadPool() override; |
16 | |
17 | void schedule(std::weak_ptr<Mailbox>) override; |
18 | |
19 | private: |
20 | std::vector<std::thread> threads; |
21 | std::queue<std::weak_ptr<Mailbox>> queue; |
22 | std::mutex mutex; |
23 | std::condition_variable cv; |
24 | bool terminate { false }; |
25 | }; |
26 | |
27 | } // namespace mbgl |
28 |