6 #include <condition_variable>
7 #pragma GCC diagnostic push
8 #pragma GCC diagnostic ignored "-Wshadow"
10 #pragma GCC diagnostic pop
11 #include <jthread.hpp>
19 AsyncPool() = default;
28 std::lock_guard lock(m_mutex);
29 m_tasks.emplace_back(std::forward<F>(f));
35 using Task = std::function<void ()>;
36 using Queue = std::deque<Task>;
39 std::condition_variable m_cond;
41 std::jthread m_thread;
43 void run(std::stop_token token) noexcept;
49 AsyncPool& instance();
52 void start() { instance().start(); }
54 void stop() { instance().stop(); }
58 void enqueue(F&& f) { instance().enqueue(std::forward<F>(f)); }