| 166 | } |
| 167 | |
| 168 | void worker_thread_executor::shutdown() { |
| 169 | const auto abort = m_atomic_abort.exchange(true, std::memory_order_relaxed); |
| 170 | if (abort) { |
| 171 | return; // shutdown had been called before. |
| 172 | } |
| 173 | |
| 174 | { |
| 175 | std::unique_lock<std::mutex> lock(m_lock); |
| 176 | m_abort = true; |
| 177 | } |
| 178 | |
| 179 | m_private_atomic_abort.store(true, std::memory_order_relaxed); |
| 180 | m_semaphore.release(); |
| 181 | |
| 182 | if (m_thread.joinable()) { |
| 183 | m_thread.join(); |
| 184 | } |
| 185 | |
| 186 | decltype(m_private_queue) private_queue; |
| 187 | decltype(m_public_queue) public_queue; |
| 188 | |
| 189 | { |
| 190 | std::unique_lock<std::mutex> lock(m_lock); |
| 191 | private_queue = std::move(m_private_queue); |
| 192 | public_queue = std::move(m_public_queue); |
| 193 | } |
| 194 | |
| 195 | private_queue.clear(); |
| 196 | public_queue.clear(); |
| 197 | } |