| 337 | |
| 338 | template<typename F> |
| 339 | auto enqueue(F&& f) -> std::future<decltype(f())> { |
| 340 | using return_type = decltype(f()); |
| 341 | |
| 342 | auto task = std::make_shared<std::packaged_task<return_type()>>( |
| 343 | std::forward<F>(f) |
| 344 | ); |
| 345 | |
| 346 | std::future<return_type> res = task->get_future(); |
| 347 | |
| 348 | { |
| 349 | std::lock_guard<std::mutex> lock(mutex); |
| 350 | pending_tasks.fetch_add(1, std::memory_order_relaxed); |
| 351 | tasks.emplace_back([task](){ (*task)(); }); |
| 352 | } |
| 353 | work_available.notify_one(); |
| 354 | |
| 355 | return res; |
| 356 | } |
| 357 | |
| 358 | template<typename F> |
| 359 | void enqueue_batch(size_t total_work, F task_func) { |
no outgoing calls