ThreadSchedule 4.1.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::scheduled_pool Class Reference

Scheduler that executes delayed and periodic tasks on worker threads. More...

#include <scheduled_pool.hpp>

Public Member Functions

 scheduled_pool ()
 Construct with default scheduler configuration.
 scheduled_pool (worker_count count)
 Construct with explicit worker count.
 scheduled_pool (scheduled_pool_config config)
 Construct from full configuration.
 scheduled_pool (scheduled_pool &&other) noexcept
auto operator= (scheduled_pool &&other) noexcept -> scheduled_pool &
 scheduled_pool (scheduled_pool const &)=delete
auto operator= (scheduled_pool const &) -> scheduled_pool &=delete
 ~scheduled_pool ()
 Shutdown scheduler and workers according to configured policy.
template<typename Rep, typename Period, typename F>
auto schedule_after (std::chrono::duration< Rep, Period > delay, F &&function) -> result< scheduled_task >
 Schedule a one-shot task to run after a delay.
template<typename F>
auto schedule_at (std::chrono::steady_clock::time_point time, F &&function) -> result< scheduled_task >
 Schedule a one-shot task at an absolute time point.
template<typename Rep, typename Period, typename F>
auto schedule_periodic (std::chrono::duration< Rep, Period > interval, F &&function) -> result< scheduled_task >
 Schedule a periodic task.
template<typename InitialRep, typename InitialPeriod, typename IntervalRep, typename IntervalPeriod, typename F>
auto schedule_periodic_after (std::chrono::duration< InitialRep, InitialPeriod > initial_delay, std::chrono::duration< IntervalRep, IntervalPeriod > interval, F &&function) -> result< scheduled_task >
 Schedule a periodic task with initial delay.
auto shutdown () -> result< void >
 Shutdown using configured shutdown policy.
auto shutdown (shutdown_policy policy) -> result< void >
 Shutdown with explicit policy.
auto scheduled_count () const -> std::size_t
 Return count of tasks currently tracked by the scheduler backend.

Static Public Member Functions

static auto create (scheduled_pool_config config={}) -> result< scheduled_pool >
 Create a scheduled pool without exceptions.

Detailed Description

Scheduler that executes delayed and periodic tasks on worker threads.

Definition at line 129 of file scheduled_pool.hpp.

Constructor & Destructor Documentation

◆ scheduled_pool() [1/5]

threadschedule::scheduled_pool::scheduled_pool ( )
inline

Construct with default scheduler configuration.

Definition at line 133 of file scheduled_pool.hpp.

References scheduled_pool().

Referenced by operator=(), operator=(), scheduled_pool(), scheduled_pool(), scheduled_pool(), and scheduled_pool().

◆ scheduled_pool() [2/5]

threadschedule::scheduled_pool::scheduled_pool ( worker_count count)
inlineexplicit

Construct with explicit worker count.

Parameters
countNumber of worker threads or automatic resolution mode.

Definition at line 139 of file scheduled_pool.hpp.

References scheduled_pool().

◆ scheduled_pool() [3/5]

threadschedule::scheduled_pool::scheduled_pool ( scheduled_pool_config config)
inlineexplicit

Construct from full configuration.

Parameters
configScheduler configuration.
Exceptions
std::system_errorif worker/scheduler thread configuration fails.

Definition at line 146 of file scheduled_pool.hpp.

References threadschedule::global_registry(), and threadschedule::detail::has_thread_configuration().

◆ scheduled_pool() [4/5]

threadschedule::scheduled_pool::scheduled_pool ( scheduled_pool && other)
inlinenoexcept

Definition at line 166 of file scheduled_pool.hpp.

References scheduled_pool().

◆ scheduled_pool() [5/5]

threadschedule::scheduled_pool::scheduled_pool ( scheduled_pool const & )
delete

References scheduled_pool().

◆ ~scheduled_pool()

threadschedule::scheduled_pool::~scheduled_pool ( )
inline

Shutdown scheduler and workers according to configured policy.

Definition at line 192 of file scheduled_pool.hpp.

Member Function Documentation

◆ create()

auto threadschedule::scheduled_pool::create ( scheduled_pool_config config = {}) ->result< scheduled_pool >
inlinestatic

Create a scheduled pool without exceptions.

Parameters
configScheduler configuration.
Returns
A ready-to-use pool or an error code.

Definition at line 203 of file scheduled_pool.hpp.

◆ operator=() [1/2]

auto threadschedule::scheduled_pool::operator= ( scheduled_pool && other) ->scheduled_pool &
inlinenoexcept

Definition at line 174 of file scheduled_pool.hpp.

References scheduled_pool().

◆ operator=() [2/2]

auto threadschedule::scheduled_pool::operator= ( scheduled_pool const & ) ->scheduled_pool &=delete
delete

References scheduled_pool().

◆ schedule_after()

template<typename Rep, typename Period, typename F>
auto threadschedule::scheduled_pool::schedule_after ( std::chrono::duration< Rep, Period > delay,
F && function )->result< scheduled_task >
inline

Schedule a one-shot task to run after a delay.

Parameters
delayRelative delay before first execution.
functionCallable to execute.
Returns
Task handle or error (for example canceled).

Definition at line 216 of file scheduled_pool.hpp.

References threadschedule::detail::checked_duration_cast(), threadschedule::detail::try_result(), and threadschedule::unexpected().

◆ schedule_at()

template<typename F>
auto threadschedule::scheduled_pool::schedule_at ( std::chrono::steady_clock::time_point time,
F && function )->result< scheduled_task >
inline

Schedule a one-shot task at an absolute time point.

Parameters
timeAbsolute steady_clock timestamp.
functionCallable to execute.

Definition at line 240 of file scheduled_pool.hpp.

References threadschedule::detail::try_result(), and threadschedule::unexpected().

◆ schedule_periodic()

template<typename Rep, typename Period, typename F>
auto threadschedule::scheduled_pool::schedule_periodic ( std::chrono::duration< Rep, Period > interval,
F && function )->result< scheduled_task >
inline

Schedule a periodic task.

Parameters
intervalExecution interval; must be > 0.
functionCallable to execute each tick.
Returns
Task handle or errc::invalid_argument for non-positive interval.

Definition at line 262 of file scheduled_pool.hpp.

References threadschedule::detail::checked_duration_cast(), threadschedule::detail::try_result(), and threadschedule::unexpected().

◆ schedule_periodic_after()

template<typename InitialRep, typename InitialPeriod, typename IntervalRep, typename IntervalPeriod, typename F>
auto threadschedule::scheduled_pool::schedule_periodic_after ( std::chrono::duration< InitialRep, InitialPeriod > initial_delay,
std::chrono::duration< IntervalRep, IntervalPeriod > interval,
F && function )->result< scheduled_task >
inline

Schedule a periodic task with initial delay.

Parameters
initial_delayDelay before first execution.
intervalPeriod between executions; must be > 0.
functionCallable to execute.

Definition at line 289 of file scheduled_pool.hpp.

References threadschedule::detail::checked_duration_cast(), threadschedule::detail::try_result(), and threadschedule::unexpected().

◆ scheduled_count()

auto threadschedule::scheduled_pool::scheduled_count ( ) const->std::size_t
inlinenodiscard

Return count of tasks currently tracked by the scheduler backend.

Definition at line 341 of file scheduled_pool.hpp.

◆ shutdown() [1/2]

auto threadschedule::scheduled_pool::shutdown ( ) ->result< void >
inline

Shutdown using configured shutdown policy.

Definition at line 316 of file scheduled_pool.hpp.

References shutdown().

Referenced by shutdown().

◆ shutdown() [2/2]

auto threadschedule::scheduled_pool::shutdown ( shutdown_policy policy) ->result< void >
inline

Shutdown with explicit policy.

Parameters
policyDrain/cancel behavior for pending tasks.

Definition at line 326 of file scheduled_pool.hpp.

References threadschedule::detail::to_native(), and threadschedule::detail::try_result().


The documentation for this class was generated from the following file: