| 17 | } |
| 18 | |
| 19 | void BackgroundThread::do_job () |
| 20 | { |
| 21 | while (true) |
| 22 | { |
| 23 | std::unique_lock<std::mutex> lck(m_mutx); |
| 24 | m_job_cond.wait(lck, [this] () -> bool { return !m_func.empty(); }); |
| 25 | auto f = m_func.front(); |
| 26 | m_func.pop(); |
| 27 | lck.unlock(); |
| 28 | f(); |
| 29 | if (m_clearing) { // All jobs before this have finished. |
| 30 | m_done_cond.notify_one(); |
| 31 | } |
| 32 | if (m_finalizing) { |
| 33 | break; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | void BackgroundThread::Submit (std::function<void()>&& a_f) |
| 39 | { |