18#include <system_error>
25template <
typename Backend>
39 template <
typename Rep,
typename Period,
typename F>
43 if (stopped_.load(std::memory_order_acquire))
44 return unexpected(std::make_error_code(std::errc::operation_canceled));
51 auto handle = impl_->schedule_after(native_delay.value(), std::forward<F>(function));
52 if (handle.is_cancelled())
53 return unexpected(std::make_error_code(std::errc::operation_canceled));
62 if (stopped_.load(std::memory_order_acquire))
63 return unexpected(std::make_error_code(std::errc::operation_canceled));
67 auto handle = impl_->schedule_at(time, std::forward<F>(function));
68 if (handle.is_cancelled())
69 return unexpected(std::make_error_code(std::errc::operation_canceled));
74 template <
typename Rep,
typename Period,
typename F>
81 if (native_interval.value() <= Backend::duration::zero())
82 return unexpected(std::make_error_code(std::errc::invalid_argument));
83 if (stopped_.load(std::memory_order_acquire))
84 return unexpected(std::make_error_code(std::errc::operation_canceled));
88 auto handle = impl_->schedule_periodic(native_interval.value(), std::forward<F>(function));
89 if (handle.is_cancelled())
90 return unexpected(std::make_error_code(std::errc::operation_canceled));
95 template <
typename InitialRep,
typename InitialPeriod,
typename IntervalRep,
typename IntervalPeriod,
typename F>
98 std::chrono::duration<IntervalRep, IntervalPeriod> interval, F&& function)
102 if (!native_interval)
104 if (native_interval.value() <= Backend::duration::zero())
105 return unexpected(std::make_error_code(std::errc::invalid_argument));
109 if (stopped_.load(std::memory_order_acquire))
110 return unexpected(std::make_error_code(std::errc::operation_canceled));
114 auto handle = impl_->schedule_periodic_after(native_delay.value(), native_interval.value(),
115 std::forward<F>(function));
116 if (handle.is_cancelled())
117 return unexpected(std::make_error_code(std::errc::operation_canceled));
126 return unexpected(std::make_error_code(std::errc::operation_canceled));
134 return unexpected(std::make_error_code(std::errc::operation_canceled));
147 stopped_.store(
true, std::memory_order_release);
155 return impl_ ? impl_->scheduled_count() : 0;
166 dispose_impl() noexcept
171 if (!impl_->is_current_context())
184 auto* backend = impl_.release();
190 std::unique_ptr<Backend> owner(backend);
207 std::unique_ptr<Backend> impl_;
208 std::atomic<bool> stopped_{
false };
scheduled_pool_facade(scheduled_pool_facade &&)=delete
auto configure_workers(thread_config const &config) -> result< void >
auto shutdown(shutdown_policy policy=shutdown_policy::drain) -> result< void >
auto schedule_at(std::chrono::steady_clock::time_point time, F &&function) -> result< scheduled_task >
auto schedule_periodic_after(std::chrono::duration< InitialRep, InitialPeriod > initial_delay, std::chrono::duration< IntervalRep, IntervalPeriod > interval, F &&function) -> result< scheduled_task >
auto configure_scheduler(thread_config const &config) -> result< void >
scheduled_pool_facade(worker_count count, worker_registration registration)
auto operator=(scheduled_pool_facade const &) -> scheduled_pool_facade &=delete
auto schedule_periodic(std::chrono::duration< Rep, Period > interval, F &&function) -> result< scheduled_task >
auto operator=(scheduled_pool_facade &&) -> scheduled_pool_facade &=delete
auto scheduled_count() const -> std::size_t
auto schedule_after(std::chrono::duration< Rep, Period > delay, F &&function) -> result< scheduled_task >
scheduled_pool_facade(scheduled_pool_facade const &)=delete
Portable thread configuration bundle.
Value type for pool worker count.
Aggregates multiple thread_registry_backend instances into a single queryable view.
constexpr auto to_native(shutdown_policy policy) noexcept -> shutdown_policy_backend
auto checked_duration_cast(std::chrono::duration< Rep, Period > value) -> expected< ToDuration, std::error_code >
auto try_result(Function &&function) -> decltype(std::forward< Function >(function)())
shutdown_policy
Defines how pools handle pending work during shutdown.
@ drain
Finish queued work before returning from shutdown.
unexpected(E) -> unexpected< E >
auto global_registry() -> thread_registry &
expected< T, std::error_code > result
Standard result type used by public APIs.
worker_registration
Controls whether pool workers are registered in a thread registry.
Error-returning result type used by the portable ThreadSchedule API.
Cancellable handle returned by scheduled task APIs.
Portable pool shutdown behavior.
static auto make(scheduled_task_backend value) -> scheduled_task
Portable thread startup and runtime configuration.
Worker-thread count configuration for pool types.
Worker registration behavior for pool-managed threads.