dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
dispenso::TimedTaskScheduler Class Reference

#include <timed_task.h>

Public Member Functions

DISPENSO_DLL_ACCESS TimedTaskScheduler (ThreadPriority priority=ThreadPriority::kNormal)
 
void setPriority (ThreadPriority priority)
 
template<typename Schedulable , typename F >
TimedTask schedule (Schedulable &sched, F &&func, double nextRunAbs, double period=0.0, size_t timesToRun=1, TimedTaskType type=TimedTaskType::kNormal)
 
template<typename Schedulable , typename Rep , typename Period , typename F >
TimedTask schedule (Schedulable &sched, F &&func, const std::chrono::duration< Rep, Period > &timeInFuture)
 
template<typename Schedulable , typename Clock , typename Duration , typename F >
TimedTask schedule (Schedulable &sched, F &&func, const std::chrono::time_point< Clock, Duration > &nextRunTime)
 
template<typename Schedulable , typename Rep , typename Period , typename F >
TimedTask schedule (Schedulable &sched, F &&func, const std::chrono::duration< Rep, Period > &timeInFuture, const std::chrono::duration< Rep, Period > &period, size_t timesToRun=std::numeric_limits< size_t >::max(), TimedTaskType type=TimedTaskType::kNormal)
 
template<typename Schedulable , typename Rep , typename Period , typename Clock , typename Duration , typename F >
TimedTask schedule (Schedulable &sched, F &&func, const std::chrono::time_point< Clock, Duration > &nextRunTime, const std::chrono::duration< Rep, Period > &period, size_t timesToRun=std::numeric_limits< size_t >::max(), TimedTaskType type=TimedTaskType::kNormal)
 

Detailed Description

A timed-task scheduler running on a single thread. This allows multiple schedulers if necessary, if e.g. you wish to schedule against InlineInvoker backing schedulable and you're running a lot of relatively quick timed tasks.Most people should just use the global timed task scheduler.

Definition at line 126 of file timed_task.h.

Constructor & Destructor Documentation

◆ TimedTaskScheduler()

dispenso::TimedTaskScheduler::TimedTaskScheduler ( ThreadPriority  priority = ThreadPriority::kNormal)
explicit

Create a TimedTaskScheduler with specified priority

Parameters
priorityThe priority to set. For highest level of periodicity accuracy, use kRealtime.
Note
Priorities above kNormal should be used sparingly, and only short-running tasks should be run inline to avoid bad OS responsivity. When using a ThreadPool Schedulable, tasks can be long running.

Definition at line 15 of file timed_task.cpp.

◆ ~TimedTaskScheduler()

dispenso::TimedTaskScheduler::~TimedTaskScheduler ( )

Definition at line 24 of file timed_task.cpp.

Member Function Documentation

◆ schedule() [1/5]

TimedTask dispenso::TimedTaskScheduler::schedule ( Schedulable sched,
F &&  func,
const std::chrono::duration< Rep, Period > &  timeInFuture 
)
inline

Schedule a task to run once at a time in the future

Parameters
schedA backing schedulable, such as ImmediateInvoker, NewThreadInvoker, TaskSet, or ThreadPool to run the function in when it is scheduled.
funcA bool() function to run when scheduled. The function may return true to indicate it should continue to be scheduled, or false to cancel.
timeInFuturethe amount of time from current at which to schedule the function

Definition at line 186 of file timed_task.h.

◆ schedule() [2/5]

TimedTask dispenso::TimedTaskScheduler::schedule ( Schedulable sched,
F &&  func,
const std::chrono::duration< Rep, Period > &  timeInFuture,
const std::chrono::duration< Rep, Period > &  period,
size_t  timesToRun = std::numeric_limits<size_t>::max(),
TimedTaskType  type = TimedTaskType::kNormal 
)
inline

Schedule a task to run periodically

Parameters
schedA backing schedulable, such as ImmediateInvoker, NewThreadInvoker, TaskSet, or ThreadPool to run the function in when it is scheduled.
funcA bool() function to run when scheduled. The function may return true to indicate it should continue to be scheduled, or false to cancel.
timeInFuturethe amount of time from current at which to schedule the function
periodThe period defining the run frequency
timesToRunThe number of times to run the function. After that number, the function will not be called again.
typeThe type of periodicity (if any).

Definition at line 222 of file timed_task.h.

◆ schedule() [3/5]

TimedTask dispenso::TimedTaskScheduler::schedule ( Schedulable sched,
F &&  func,
const std::chrono::time_point< Clock, Duration > &  nextRunTime 
)
inline

Schedule a task to run once at a time in the future

Parameters
schedA backing schedulable, such as ImmediateInvoker, NewThreadInvoker, TaskSet, or ThreadPool to run the function in when it is scheduled.
funcA bool() function to run when scheduled. The function may return true to indicate it should continue to be scheduled, or false to cancel.
nextRunTimeAn absolute time to run the function. If in the past, func will run immediately.

Definition at line 201 of file timed_task.h.

◆ schedule() [4/5]

TimedTask dispenso::TimedTaskScheduler::schedule ( Schedulable sched,
F &&  func,
const std::chrono::time_point< Clock, Duration > &  nextRunTime,
const std::chrono::duration< Rep, Period > &  period,
size_t  timesToRun = std::numeric_limits<size_t>::max(),
TimedTaskType  type = TimedTaskType::kNormal 
)
inline

Schedule a task to run periodically

Parameters
schedA backing schedulable, such as ImmediateInvoker, NewThreadInvoker, TaskSet, or ThreadPool to run the function in when it is scheduled.
funcA bool() function to run when scheduled. The function may return true to indicate it should continue to be scheduled, or false to cancel.
nextRunTimeAn absolute time to run the function. If in the past, func will run immediately.
periodThe period defining the run frequency
timesToRunThe number of times to run the function. After that number, the function will not be called again.
typeThe type of periodicity (if any).

Definition at line 254 of file timed_task.h.

◆ schedule() [5/5]

TimedTask dispenso::TimedTaskScheduler::schedule ( Schedulable sched,
F &&  func,
double  nextRunAbs,
double  period = 0.0,
size_t  timesToRun = 1,
TimedTaskType  type = TimedTaskType::kNormal 
)
inline

Schedule a task

Parameters
schedA backing schedulable, such as ImmediateInvoker, NewThreadInvoker, TaskSet, or ThreadPool to run the function in when it is scheduled.
funcA bool() function to run when scheduled. The function may return true to indicate it should continue to be scheduled, or false to cancel.
nextRunAbsThe absolute time to run the function. Time scale is expected to match getTime() for absolute times.
periodThe period in seconds.
timesToRunThe number of times to run the function. After that number, the function will not be called again.
typeThe type of periodicity (if any).

Definition at line 163 of file timed_task.h.

◆ setPriority()

void dispenso::TimedTaskScheduler::setPriority ( ThreadPriority  priority)
inline

Set the priority for the backing thread. See note for constructor.

Definition at line 143 of file timed_task.h.


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