TrinityCore
|
#include <TaskScheduler.h>
Classes | |
struct | Compare |
Container which provides Task order, insert and reschedule operations. More... | |
class | Task |
class | TaskQueue |
Public Member Functions | |
TaskScheduler () | |
template<typename P > | |
TaskScheduler (P &&predicate) | |
TaskScheduler (TaskScheduler const &)=delete | |
TaskScheduler (TaskScheduler &&)=delete | |
TaskScheduler & | operator= (TaskScheduler const &)=delete |
TaskScheduler & | operator= (TaskScheduler &&)=delete |
~TaskScheduler ()=default | |
template<typename P > | |
TaskScheduler & | SetValidator (P &&predicate) |
Sets a validator which is asked if tasks are allowed to be executed. More... | |
TaskScheduler & | ClearValidator () |
Clears the validator which is asked if tasks are allowed to be executed. More... | |
TaskScheduler & | Update (success_t const &callback=nullptr) |
TaskScheduler & | Update (size_t milliseconds, success_t const &callback=nullptr) |
template<class Rep , class Period > | |
TaskScheduler & | Update (std::chrono::duration< Rep, Period > difftime, success_t const &callback=nullptr) |
TaskScheduler & | Async (std::function< void()> callable) |
template<class Rep , class Period > | |
TaskScheduler & | Schedule (std::chrono::duration< Rep, Period > time, task_handler_t task) |
template<class Rep , class Period > | |
TaskScheduler & | Schedule (std::chrono::duration< Rep, Period > time, group_t const group, task_handler_t task) |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskScheduler & | Schedule (std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max, task_handler_t task) |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskScheduler & | Schedule (std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max, group_t const group, task_handler_t task) |
TaskScheduler & | CancelAll () |
TaskScheduler & | CancelGroup (group_t group) |
TaskScheduler & | CancelGroupsOf (std::vector< group_t > const &groups) |
template<class Rep , class Period > | |
TaskScheduler & | DelayAll (std::chrono::duration< Rep, Period > duration) |
Delays all tasks with the given duration. More... | |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskScheduler & | DelayAll (std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max) |
Delays all tasks with a random duration between min and max. More... | |
template<class Rep , class Period > | |
TaskScheduler & | DelayGroup (group_t const group, std::chrono::duration< Rep, Period > duration) |
Delays all tasks of a group with the given duration. More... | |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskScheduler & | DelayGroup (group_t const group, std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max) |
Delays all tasks of a group with a random duration between min and max. More... | |
template<class Rep , class Period > | |
TaskScheduler & | RescheduleAll (std::chrono::duration< Rep, Period > duration) |
Reschedule all tasks with a given duration. More... | |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskScheduler & | RescheduleAll (std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max) |
Reschedule all tasks with a random duration between min and max. More... | |
template<class Rep , class Period > | |
TaskScheduler & | RescheduleGroup (group_t const group, std::chrono::duration< Rep, Period > duration) |
Reschedule all tasks of a group with the given duration. More... | |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskScheduler & | RescheduleGroup (group_t const group, std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max) |
Reschedule all tasks of a group with a random duration between min and max. More... | |
Private Types | |
typedef std::chrono::steady_clock | clock_t |
typedef clock_t::time_point | timepoint_t |
typedef clock_t::duration | duration_t |
typedef uint32 | group_t |
typedef uint32 | repeated_t |
typedef std::function< void(TaskContext)> | task_handler_t |
typedef std::function< bool()> | predicate_t |
typedef std::function< void()> | success_t |
typedef std::shared_ptr< Task > | TaskContainer |
typedef std::queue< std::function< void()> > | AsyncHolder |
Private Member Functions | |
TaskScheduler & | InsertTask (TaskContainer task) |
Insert a new task to the enqueued tasks. More... | |
template<class Rep , class Period > | |
TaskScheduler & | ScheduleAt (timepoint_t end, std::chrono::duration< Rep, Period > time, task_handler_t task) |
template<class Rep , class Period > | |
TaskScheduler & | ScheduleAt (timepoint_t end, std::chrono::duration< Rep, Period > time, group_t const group, task_handler_t task) |
void | Dispatch (success_t const &callback) |
Dispatch remaining tasks. More... | |
Static Private Member Functions | |
static bool | EmptyValidator () |
Private Attributes | |
std::shared_ptr< TaskScheduler > | self_reference |
Contains a self reference to track if this object was deleted or not. More... | |
timepoint_t | _now |
The current time point (now) More... | |
TaskQueue | _task_holder |
The Task Queue which contains all task objects. More... | |
AsyncHolder | _asyncHolder |
predicate_t | _predicate |
Friends | |
class | TaskContext |
The TaskScheduler class provides the ability to schedule std::function's in the near future. Use TaskScheduler::Update to update the scheduler. Popular methods are:
Definition at line 47 of file TaskScheduler.h.
|
private |
Definition at line 160 of file TaskScheduler.h.
|
private |
Definition at line 52 of file TaskScheduler.h.
|
private |
Definition at line 54 of file TaskScheduler.h.
|
private |
Definition at line 57 of file TaskScheduler.h.
|
private |
Definition at line 63 of file TaskScheduler.h.
|
private |
Definition at line 59 of file TaskScheduler.h.
|
private |
Definition at line 65 of file TaskScheduler.h.
|
private |
Definition at line 61 of file TaskScheduler.h.
|
private |
Definition at line 118 of file TaskScheduler.h.
|
private |
Definition at line 53 of file TaskScheduler.h.
|
inline |
Definition at line 174 of file TaskScheduler.h.
|
inline |
Definition at line 178 of file TaskScheduler.h.
|
delete |
|
delete |
|
default |
TaskScheduler & TaskScheduler::Async | ( | std::function< void()> | callable | ) |
Schedule an callable function that is executed at the next update tick. Its safe to modify the TaskScheduler from within the callable.
Definition at line 39 of file TaskScheduler.cpp.
TaskScheduler & TaskScheduler::CancelAll | ( | ) |
Cancels all tasks. Never call this from within a task context! Use TaskContext::CancelAll instead!
Clear the task holder
Definition at line 45 of file TaskScheduler.cpp.
TaskScheduler & TaskScheduler::CancelGroup | ( | group_t | group | ) |
Cancel all tasks of a single group. Never call this from within a task context! Use TaskContext::CancelGroup instead!
Definition at line 53 of file TaskScheduler.cpp.
TaskScheduler & TaskScheduler::CancelGroupsOf | ( | std::vector< group_t > const & | groups | ) |
Cancels all groups in the given std::vector. Hint: Use std::initializer_list for this: "{1, 2, 3, 4}"
Definition at line 62 of file TaskScheduler.cpp.
TaskScheduler & TaskScheduler::ClearValidator | ( | ) |
Clears the validator which is asked if tasks are allowed to be executed.
Definition at line 21 of file TaskScheduler.cpp.
|
inline |
Delays all tasks with the given duration.
Definition at line 273 of file TaskScheduler.h.
|
inline |
Delays all tasks with a random duration between min and max.
Definition at line 285 of file TaskScheduler.h.
|
inline |
Delays all tasks of a group with the given duration.
Definition at line 293 of file TaskScheduler.h.
|
inline |
Delays all tasks of a group with a random duration between min and max.
Definition at line 310 of file TaskScheduler.h.
|
private |
Dispatch remaining tasks.
Definition at line 76 of file TaskScheduler.cpp.
|
inlinestaticprivate |
|
private |
Insert a new task to the enqueued tasks.
Definition at line 70 of file TaskScheduler.cpp.
|
delete |
|
delete |
|
inline |
Reschedule all tasks with a given duration.
Definition at line 319 of file TaskScheduler.h.
|
inline |
Reschedule all tasks with a random duration between min and max.
Definition at line 332 of file TaskScheduler.h.
|
inline |
Reschedule all tasks of a group with the given duration.
Definition at line 340 of file TaskScheduler.h.
|
inline |
Reschedule all tasks of a group with a random duration between min and max.
Definition at line 358 of file TaskScheduler.h.
|
inline |
Schedule an event with a fixed rate. Never call this from within a task context! Use TaskContext::Schedule instead!
Definition at line 234 of file TaskScheduler.h.
|
inline |
Schedule an event with a fixed rate. Never call this from within a task context! Use TaskContext::Schedule instead!
Definition at line 225 of file TaskScheduler.h.
|
inline |
Schedule an event with a fixed rate. Never call this from within a task context! Use TaskContext::Schedule instead!
Definition at line 252 of file TaskScheduler.h.
|
inline |
Schedule an event with a randomized rate between min and max rate. Never call this from within a task context! Use TaskContext::Schedule instead!
Definition at line 243 of file TaskScheduler.h.
|
inlineprivate |
Schedule an event with a fixed rate. Never call this from within a task context! Use TaskContext::schedule instead!
Definition at line 379 of file TaskScheduler.h.
|
inlineprivate |
|
inline |
Sets a validator which is asked if tasks are allowed to be executed.
Definition at line 190 of file TaskScheduler.h.
TaskScheduler & TaskScheduler::Update | ( | size_t | milliseconds, |
success_t const & | callback = nullptr |
||
) |
Update the scheduler with a difftime in ms. Calls the optional callback on successfully finish.
Definition at line 34 of file TaskScheduler.cpp.
|
inline |
Update the scheduler with a difftime. Calls the optional callback on successfully finish.
Definition at line 210 of file TaskScheduler.h.
TaskScheduler & TaskScheduler::Update | ( | success_t const & | callback = nullptr | ) |
Update the scheduler to the current time. Calls the optional callback on successfully finish.
Definition at line 27 of file TaskScheduler.cpp.
|
friend |
Definition at line 49 of file TaskScheduler.h.
|
private |
Contains all asynchronous tasks which will be invoked at the next update tick.
Definition at line 164 of file TaskScheduler.h.
|
private |
The current time point (now)
Definition at line 155 of file TaskScheduler.h.
|
private |
Definition at line 166 of file TaskScheduler.h.
|
private |
The Task Queue which contains all task objects.
Definition at line 158 of file TaskScheduler.h.
|
private |
Contains a self reference to track if this object was deleted or not.
Definition at line 152 of file TaskScheduler.h.