| 169 | } |
| 170 | |
| 171 | bool streamfx::util::threadpool::threadpool::die(std::shared_ptr<worker_info> wi) |
| 172 | { |
| 173 | constexpr std::chrono::seconds delay{1}; |
| 174 | |
| 175 | std::lock_guard<std::mutex> lg(_workers_lock); |
| 176 | bool result = false; |
| 177 | |
| 178 | if (_worker_count > _limits.first) { |
| 179 | auto now = std::chrono::high_resolution_clock::now(); |
| 180 | result = ((wi->last_work_time + delay) <= now) && ((_last_worker_death + delay) <= now); |
| 181 | |
| 182 | if (result) { |
| 183 | _last_worker_death = now; |
| 184 | --_worker_count; |
| 185 | _workers.remove(wi); |
| 186 | D_LOG_DEBUG("Terminated idle worker thread (%zu < %zu < %zu).", _limits.first, _worker_count.load(), _limits.second); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return result; |
| 191 | } |
| 192 | |
| 193 | void streamfx::util::threadpool::threadpool::work(std::shared_ptr<worker_info> wi) |
| 194 | { |