32 using original_worker =
decltype(new_thread::create_worker());
37 worker_strategy(
const original_worker& original_worker)
38 : m_original_worker{original_worker}
43 void defer_for(duration duration, Fn&& fn, Handler&& handler, Args&&... args)
const
45 m_original_worker.schedule(duration, std::forward<Fn>(fn), std::forward<Handler>(handler), std::forward<Args>(args)...);
49 void defer_to(time_point tp, Fn&& fn, Handler&& handler, Args&&... args)
const
51 m_original_worker.schedule(tp, std::forward<Fn>(fn), std::forward<Handler>(handler), std::forward<Args>(args)...);
54 static rpp::schedulers::time_point now() {
return original_worker::now(); }
57 original_worker m_original_worker;
61 explicit thread_pool(
size_t threads_count = std::thread::hardware_concurrency())
62 : m_state{std::make_shared<state>(threads_count)}
75 explicit state(
size_t threads_count)
77 threads_count = std::max(
size_t{1}, threads_count);
78 m_workers.reserve(threads_count);
79 for (
size_t i = 0; i < threads_count; ++i)
80 m_workers.emplace_back(new_thread::create_worker());
83 const original_worker& get() {
return m_workers[m_index++ % m_workers.size()]; }
86 std::vector<original_worker> m_workers{};
90 std::shared_ptr<state> m_state{};