7 #include <condition_variable>
16 typedef std::function<void(
void)>
func;
22 std::vector<std::thread> m_Threads;
28 std::condition_variable m_Condition;
31 std::queue<func> m_Tasks;
44 for (
size_t i = 0; i <= num_threads; ++i) {
47 m_Threads.emplace_back(
51 std::function<void()> task;
55 std::unique_lock<std::mutex> lock(this->mu);
56 this->m_Condition.wait(lock,
57 [
this]{
return this->quit || !this->m_Tasks.empty(); });
63 task = std::move(this->m_Tasks.front());
78 { std::unique_lock<std::mutex> lock(mu);
82 m_Condition.notify_all();
83 for(std::thread &worker: m_Threads)
96 std::unique_lock<std::mutex> lock(mu);
100 throw std::runtime_error(
"enqueue on stopped JobSystem");
102 m_Tasks.emplace([job](){ job(); });
104 m_Condition.notify_one();