| 46 | { |
| 47 | |
| 48 | class ThreadPool |
| 49 | { |
| 50 | public: |
| 51 | // After numThreads tasks are actively running, and queueSize tasks have |
| 52 | // been enqueued to wait for an available worker thread, subsequent calls |
| 53 | // to Pool::add will block until an enqueued task has been popped from the |
| 54 | // queue. |
| 55 | PDAL_EXPORT ThreadPool(std::size_t numThreads, int64_t queueSize = -1, |
| 56 | bool verbose = true) : |
| 57 | m_queueSize(queueSize), |
| 58 | m_numThreads(std::max<std::size_t>(numThreads, 1)) |
| 59 | { |
| 60 | assert(m_queueSize != 0); |
| 61 | go(); |
| 62 | } |
| 63 | |
| 64 | PDAL_EXPORT ~ThreadPool() |
| 65 | { join(); } |
| 66 | |
| 67 | ThreadPool(const ThreadPool& other) = delete; |
| 68 | ThreadPool& operator=(const ThreadPool& other) = delete; |