| 95 | } |
| 96 | |
| 97 | void ThreadPool::ThreadProc() |
| 98 | { |
| 99 | while(!m_terminate.load()) |
| 100 | { |
| 101 | std::shared_ptr<ThreadPoolTask> task; |
| 102 | |
| 103 | // Wait until a task is available or termination is requested |
| 104 | { |
| 105 | std::unique_lock<std::mutex> lock(m_mutex); |
| 106 | m_forward.wait(lock, [this] { return !m_tasks.empty() || m_terminate.load(); }); |
| 107 | |
| 108 | if (!m_tasks.empty()) |
| 109 | { |
| 110 | task = std::move(m_tasks.front()); |
| 111 | m_tasks.pop(); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if (task) |
| 116 | { |
| 117 | try |
| 118 | { |
| 119 | task->Run(); |
| 120 | } |
| 121 | catch(...) |
| 122 | { |
| 123 | // Ignore task exceptions |
| 124 | } |
| 125 | --m_pendingTasks; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | } |
no test coverage detected