2021-09-18 22:08:46 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
class thread_pool
|
|
|
|
{
|
|
|
|
std::atomic<bool> m_accept_jobs;
|
|
|
|
std::condition_variable m_data_condition;
|
|
|
|
|
|
|
|
std::stack<std::function<void()>> m_job_stack;
|
|
|
|
std::mutex m_lock;
|
|
|
|
std::vector<std::thread> m_thread_pool;
|
|
|
|
|
|
|
|
std::thread m_managing_thread;
|
2023-03-01 21:27:15 +00:00
|
|
|
|
2021-09-18 22:08:46 +02:00
|
|
|
public:
|
|
|
|
thread_pool();
|
|
|
|
~thread_pool();
|
|
|
|
|
|
|
|
void destroy();
|
|
|
|
void push(std::function<void()> func);
|
2023-03-01 21:27:15 +00:00
|
|
|
|
2021-09-18 22:08:46 +02:00
|
|
|
private:
|
|
|
|
void create();
|
|
|
|
void done();
|
|
|
|
void run();
|
|
|
|
};
|
|
|
|
|
|
|
|
inline thread_pool* g_thread_pool{};
|
|
|
|
}
|