ThreadSchedule 1.0.0
Modern C++ thread management library
|
Thread pool with support for scheduled and periodic tasks. More...
#include <scheduled_pool.hpp>
Classes | |
struct | ScheduledTaskInfo |
Public Types | |
using | Task = std::function<void()> |
using | TimePoint = std::chrono::steady_clock::time_point |
using | Duration = std::chrono::steady_clock::duration |
Public Member Functions | |
ScheduledThreadPoolT (size_t worker_threads=std::thread::hardware_concurrency()) | |
Create a scheduled thread pool. | |
ScheduledThreadPoolT (ScheduledThreadPoolT const &)=delete | |
auto | operator= (ScheduledThreadPoolT const &) -> ScheduledThreadPoolT &=delete |
auto | schedule_after (Duration delay, Task task) -> ScheduledTaskHandle |
Schedule a task to run after a delay. | |
auto | schedule_at (TimePoint time_point, Task task) -> ScheduledTaskHandle |
Schedule a task to run at a specific time point. | |
auto | schedule_periodic (Duration interval, Task task) -> ScheduledTaskHandle |
Schedule a task to run periodically at fixed intervals. | |
auto | schedule_periodic_after (Duration initial_delay, Duration interval, Task task) -> ScheduledTaskHandle |
Schedule a task to run periodically after an initial delay. | |
auto | scheduled_count () const -> size_t |
Get number of scheduled tasks (including periodic) | |
auto | thread_pool () -> PoolType & |
Get the underlying thread pool for direct task submission. | |
void | shutdown () |
Shutdown the scheduler and wait for completion. | |
auto | configure_threads (std::string const &name_prefix, SchedulingPolicy policy=SchedulingPolicy::OTHER, ThreadPriority priority=ThreadPriority::normal()) |
Configure worker threads. |
Static Public Member Functions | |
static void | cancel (ScheduledTaskHandle &handle) |
Cancel a scheduled task by handle. |
Thread pool with support for scheduled and periodic tasks.
Features:
PoolType | Type of thread pool to use for task execution (default: ThreadPool) |
Definition at line 66 of file scheduled_pool.hpp.
using threadschedule::ScheduledThreadPoolT< PoolType >::Duration = std::chrono::steady_clock::duration |
Definition at line 71 of file scheduled_pool.hpp.
using threadschedule::ScheduledThreadPoolT< PoolType >::Task = std::function<void()> |
Definition at line 69 of file scheduled_pool.hpp.
using threadschedule::ScheduledThreadPoolT< PoolType >::TimePoint = std::chrono::steady_clock::time_point |
Definition at line 70 of file scheduled_pool.hpp.
|
inlineexplicit |
Create a scheduled thread pool.
worker_threads | Number of worker threads for executing tasks (default: hardware concurrency) |
Definition at line 87 of file scheduled_pool.hpp.
|
inline |
Definition at line 96 of file scheduled_pool.hpp.
|
inlinestatic |
Cancel a scheduled task by handle.
handle | Handle returned from schedule_* functions |
Note: Can also call handle.cancel() directly
Definition at line 188 of file scheduled_pool.hpp.
|
inline |
Configure worker threads.
Note: Return type depends on the underlying pool type. ThreadPool returns bool, HighPerformancePool returns expected<void, std::error_code>. For consistent behavior, access the pool directly via thread_pool().
Definition at line 239 of file scheduled_pool.hpp.
|
inline |
Schedule a task to run after a delay.
delay | Duration to wait before executing the task |
task | Function to execute |
Definition at line 107 of file scheduled_pool.hpp.
|
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 119 of file scheduled_pool.hpp.
Referenced by threadschedule::ScheduledThreadPoolT< ThreadPool >::schedule_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 149 of file scheduled_pool.hpp.
|
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 161 of file scheduled_pool.hpp.
Referenced by threadschedule::ScheduledThreadPoolT< ThreadPool >::schedule_periodic().
|
inlinenodiscard |
Get number of scheduled tasks (including periodic)
Definition at line 196 of file scheduled_pool.hpp.
|
inline |
Shutdown the scheduler and wait for completion.
Definition at line 213 of file scheduled_pool.hpp.
|
inlinenodiscard |
Get the underlying thread pool for direct task submission.
Definition at line 205 of file scheduled_pool.hpp.