|
ThreadSchedule 3.0.0
Modern C++ thread management library
|
Thread pool augmented with delayed and periodic task scheduling. More...
#include <scheduled_pool_backend_base.hpp>
Classes | |
| struct | periodic_task_state |
| struct | scheduled_dispatch_state |
| class | scheduled_task_info |
Public Types | |
| using | task_type = std::function< void()> |
| using | one_shot_task_type = detail::move_only_function< void()> |
| using | periodic_task_type = detail::move_only_function< void()> |
| using | time_point = std::chrono::steady_clock::time_point |
| using | duration = std::chrono::steady_clock::duration |
Public Member Functions | |
| scheduled_pool_backend_base (size_t worker_threads=default_worker_count()) | |
| Create a scheduled thread pool. | |
| template<typename T = PoolType, std::enable_if_t< std::is_constructible_v< T, size_t, bool >, int > = 0> | |
| scheduled_pool_backend_base (size_t worker_threads, bool register_workers) | |
| scheduled_pool_backend_base (scheduled_pool_backend_base const &)=delete | |
| auto | operator= (scheduled_pool_backend_base const &) -> scheduled_pool_backend_base &=delete |
| ~scheduled_pool_backend_base () | |
| auto | schedule_after (duration delay, task_type task) -> scheduled_task_backend |
| Schedule a task to run after a delay. | |
| template<typename F , std::enable_if_t<!std::is_same_v< detail::remove_cvref_t< F >, task_type >, int > = 0> | |
| auto | schedule_after (duration delay, F &&task) -> scheduled_task_backend |
| auto | schedule_at (time_point time_point, task_type task) -> scheduled_task_backend |
| Schedule a task to run at a specific time point. | |
| template<typename F , std::enable_if_t<!std::is_same_v< detail::remove_cvref_t< F >, task_type >, int > = 0> | |
| auto | schedule_at (time_point time_point, F &&task) -> scheduled_task_backend |
| auto | schedule_periodic (duration interval, task_type task) -> scheduled_task_backend |
| Schedule a task to run periodically at fixed intervals. | |
| template<typename F , std::enable_if_t<!std::is_same_v< detail::remove_cvref_t< F >, task_type >, int > = 0> | |
| auto | schedule_periodic (duration interval, F &&task) -> scheduled_task_backend |
| auto | schedule_periodic_after (duration initial_delay, duration interval, task_type task) -> scheduled_task_backend |
| Schedule a task to run periodically after an initial delay. | |
| template<typename F , std::enable_if_t<!std::is_same_v< detail::remove_cvref_t< F >, task_type >, int > = 0> | |
| auto | schedule_periodic_after (duration initial_delay, duration interval, F &&task) -> scheduled_task_backend |
| auto | scheduled_count () const -> size_t |
| Get number of scheduled tasks (including periodic) | |
| auto | is_current_context () const noexcept -> bool |
| auto | thread_pool () -> PoolType & |
| Get the underlying thread pool for direct task submission. | |
| void | shutdown (shutdown_policy_backend policy=shutdown_policy_backend::drain) |
| Shutdown the scheduler and wait for completion. | |
| auto | configure_threads (std::string const &name_prefix, native_scheduling_policy policy=native_scheduling_policy::other, native_thread_priority priority=native_thread_priority::normal()) |
| Configure worker threads. | |
| auto | configure_threads (native_thread_config const &config) -> expected< void, std::error_code > |
| auto | scheduler_thread_info () const -> std::optional< thread_info > |
| auto | configure_scheduler_thread (std::string const &name, native_scheduling_policy policy=native_scheduling_policy::other, native_thread_priority priority=native_thread_priority::normal()) -> expected< void, std::error_code > |
| auto | configure_scheduler_thread (native_thread_config const &config) -> expected< void, std::error_code > |
Static Public Member Functions | |
| static void | cancel (scheduled_task_backend &handle) |
| Cancel a scheduled task by handle. | |
Thread pool augmented with delayed and periodic task scheduling.
Non-copyable, non-movable. Combines a dedicated scheduler thread with an underlying PoolType (default: thread_pool_backend) that does the actual work.
thread_pool_backend, polling_pool_backend, work_stealing_pool_backend, or lightweight_pool_backend documentation).| PoolType | Thread pool used for task execution (default: thread_pool_backend). |
Definition at line 104 of file scheduled_pool_backend_base.hpp.
| using threadschedule::detail::scheduled_pool_backend_base< PoolType >::duration = std::chrono::steady_clock::duration |
Definition at line 111 of file scheduled_pool_backend_base.hpp.
| using threadschedule::detail::scheduled_pool_backend_base< PoolType >::one_shot_task_type = detail::move_only_function<void()> |
Definition at line 108 of file scheduled_pool_backend_base.hpp.
| using threadschedule::detail::scheduled_pool_backend_base< PoolType >::periodic_task_type = detail::move_only_function<void()> |
Definition at line 109 of file scheduled_pool_backend_base.hpp.
| using threadschedule::detail::scheduled_pool_backend_base< PoolType >::task_type = std::function<void()> |
Definition at line 107 of file scheduled_pool_backend_base.hpp.
| using threadschedule::detail::scheduled_pool_backend_base< PoolType >::time_point = std::chrono::steady_clock::time_point |
Definition at line 110 of file scheduled_pool_backend_base.hpp.
|
inlineexplicit |
Create a scheduled thread pool.
| worker_threads | Number of worker threads for executing tasks (default: hardware concurrency) |
Definition at line 250 of file scheduled_pool_backend_base.hpp.
|
inline |
Definition at line 257 of file scheduled_pool_backend_base.hpp.
|
delete |
|
inline |
Definition at line 266 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::scheduled_pool_backend_base< PoolType >::shutdown().
|
inlinestatic |
Cancel a scheduled task by handle.
| handle | Handle returned from schedule_* functions |
Note: Can also call handle.cancel() directly
Definition at line 381 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::scheduled_task_backend::cancel().
|
inline |
Definition at line 488 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::scheduled_pool_backend_base< PoolType >::scheduler_thread_info().
|
inline |
Definition at line 477 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::configure_thread(), and threadschedule::detail::scheduled_pool_backend_base< PoolType >::scheduler_thread_info().
|
inline |
Definition at line 460 of file scheduled_pool_backend_base.hpp.
|
inline |
Configure worker threads.
Returns expected<void, std::error_code> from the underlying pool.
Definition at line 453 of file scheduled_pool_backend_base.hpp.
|
inlinenoexcept |
Definition at line 397 of file scheduled_pool_backend_base.hpp.
Referenced by threadschedule::detail::scheduled_pool_backend_base< PoolType >::shutdown().
|
delete |
|
inline |
Definition at line 288 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::checked_deadline_after(), and threadschedule::detail::make_move_only_function().
|
inline |
Schedule a task to run after a delay.
| delay | duration to wait before executing the task |
| task | Function to execute |
Definition at line 278 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::checked_deadline_after(), and threadschedule::detail::make_move_only_function().
|
inline |
Definition at line 310 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::make_move_only_function().
|
inline |
Schedule a task to run at a specific time point.
| time_point | When to execute the task |
| task | Function to execute |
Definition at line 303 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::make_move_only_function().
|
inline |
Definition at line 332 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::scheduled_pool_backend_base< PoolType >::schedule_periodic_after().
|
inline |
Schedule a task to run periodically at fixed intervals.
| interval | duration between executions |
| task | Function to execute repeatedly |
The task runs immediately and then repeats every interval. Use schedule_periodic_after() if you want to delay the first execution.
Definition at line 325 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::scheduled_pool_backend_base< PoolType >::schedule_periodic_after().
|
inline |
Definition at line 360 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::checked_deadline_after(), and threadschedule::detail::make_move_only_function().
|
inline |
Schedule a task to run periodically after an initial delay.
| initial_delay | duration to wait before first execution |
| interval | duration between subsequent executions |
| task | Function to execute repeatedly |
Definition at line 345 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::checked_deadline_after(), and threadschedule::detail::make_move_only_function().
Referenced by threadschedule::detail::scheduled_pool_backend_base< PoolType >::schedule_periodic(), and threadschedule::detail::scheduled_pool_backend_base< PoolType >::schedule_periodic().
|
inline |
Get number of scheduled tasks (including periodic)
Definition at line 390 of file scheduled_pool_backend_base.hpp.
|
inline |
Definition at line 466 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::thread_info::get_thread_id(), and threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::joinable().
Referenced by threadschedule::detail::scheduled_pool_backend_base< PoolType >::configure_scheduler_thread(), and threadschedule::detail::scheduled_pool_backend_base< PoolType >::configure_scheduler_thread().
|
inline |
Shutdown the scheduler and wait for completion.
Definition at line 415 of file scheduled_pool_backend_base.hpp.
References threadschedule::detail::scheduled_pool_backend_base< PoolType >::is_current_context(), threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::join(), threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::joinable(), and threadschedule::detail::throw_worker_deadlock().
Referenced by threadschedule::detail::scheduled_pool_backend_base< PoolType >::~scheduled_pool_backend_base().
|
inline |
Get the underlying thread pool for direct task submission.
Definition at line 406 of file scheduled_pool_backend_base.hpp.