| 121 | impl->taskCount.release(); |
| 122 | } |
| 123 | std::shared_ptr<data::CancellableCallback> |
| 124 | ThreadPoolExecutor::executeAfter(std::function<void()> f, Duration dur) const { |
| 125 | if (dur <= Duration{0}) { |
| 126 | execute(std::move(f)); |
| 127 | return nullptr; |
| 128 | } else { |
| 129 | auto& worker = impl->getScheduledWorker(*this); |
| 130 | auto res = std::make_shared<data::CancellableCallback>(std::move(f)); |
| 131 | worker.works.emplace(Clock::now() + dur, res); |
| 132 | worker.sleeper.interrupt(); |
| 133 | return res; |
| 134 | } |
| 135 | } |
| 136 | ThreadPoolExecutor const& ThreadPoolExecutor::getDefault() { |
| 137 | static ThreadPoolExecutor ins("ll_default_thread_pool", std::max((int)std::thread::hardware_concurrency() - 2, 2)); |
| 138 | return ins; |