12 TaskPool(
unsigned int count = std::thread::hardware_concurrency()) {
13 getSystemLogger()->info(
"Creating {} thread runners", count);
15 for (
unsigned int i = 0; i < count; ++i) {
16 m_pool.emplace_back(std::bind_front(&TaskPool::Runner,
this), i + 1);
20 void push(std::function<
void()>
func) {
21 m_taskQueue.push(std::move(
func));
25 getSystemLogger()->info(
"Destroying {} thread runners", m_pool.size());
27 for (
auto &thread : m_pool) {
28 thread.request_stop();
34 std::vector<std::jthread> m_pool;
38 std::condition_variable m_cond;
40 void Runner(
const std::stop_token token,
int ) {
41 while (!token.stop_requested()) {
42 std::unique_lock<std::mutex> lock(m_mutex);
44 m_cond.wait(lock, [
this, &token]() {
return !m_taskQueue.empty() || token.stop_requested(); });
49 if (!m_taskQueue.empty() && !token.stop_requested()) {
50 auto func = m_taskQueue.pop();