![]() |
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 |
| template<typename P > | |
| TaskScheduler & | SetValidator (P &&predicate) |
| Sets a validator which is asked if tasks are allowed to be executed. | |
| TaskScheduler & | ClearValidator () |
| Clears the validator which is asked if tasks are allowed to be executed. | |
| TaskScheduler & | Update (success_t const &callback=EmptyCallback) |
| TaskScheduler & | Update (size_t const milliseconds, success_t const &callback=EmptyCallback) |
| template<class _Rep , class _Period > | |
| TaskScheduler & | Update (std::chrono::duration< _Rep, _Period > const &difftime, success_t const &callback=EmptyCallback) |
| TaskScheduler & | Async (std::function< void()> const &callable) |
| template<class _Rep , class _Period > | |
| TaskScheduler & | Schedule (std::chrono::duration< _Rep, _Period > const &time, task_handler_t const &task) |
| template<class _Rep , class _Period > | |
| TaskScheduler & | Schedule (std::chrono::duration< _Rep, _Period > const &time, group_t const group, task_handler_t const &task) |
| template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight > | |
| TaskScheduler & | Schedule (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max, task_handler_t const &task) |
| template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight > | |
| TaskScheduler & | Schedule (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max, group_t const group, task_handler_t const &task) |
| TaskScheduler & | CancelAll () |
| TaskScheduler & | CancelGroup (group_t const group) |
| TaskScheduler & | CancelGroupsOf (std::vector< group_t > const &groups) |
| template<class _Rep , class _Period > | |
| TaskScheduler & | DelayAll (std::chrono::duration< _Rep, _Period > const &duration) |
| Delays all tasks with the given duration. | |
| template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight > | |
| TaskScheduler & | DelayAll (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
| Delays all tasks with a random duration between min and max. | |
| template<class _Rep , class _Period > | |
| TaskScheduler & | DelayGroup (group_t const group, std::chrono::duration< _Rep, _Period > const &duration) |
| Delays all tasks of a group with the given duration. | |
| template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight > | |
| TaskScheduler & | DelayGroup (group_t const group, std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
| Delays all tasks of a group with a random duration between min and max. | |
| template<class _Rep , class _Period > | |
| TaskScheduler & | RescheduleAll (std::chrono::duration< _Rep, _Period > const &duration) |
| Reschedule all tasks with a given duration. | |
| template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight > | |
| TaskScheduler & | RescheduleAll (std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
| Reschedule all tasks with a random duration between min and max. | |
| template<class _Rep , class _Period > | |
| TaskScheduler & | RescheduleGroup (group_t const group, std::chrono::duration< _Rep, _Period > const &duration) |
| Reschedule all tasks of a group with the given duration. | |
| template<class _RepLeft , class _PeriodLeft , class _RepRight , class _PeriodRight > | |
| TaskScheduler & | RescheduleGroup (group_t const group, std::chrono::duration< _RepLeft, _PeriodLeft > const &min, std::chrono::duration< _RepRight, _PeriodRight > const &max) |
| Reschedule all tasks of a group with a random duration between min and max. | |
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. | |
| template<class _Rep , class _Period > | |
| TaskScheduler & | ScheduleAt (timepoint_t const &end, std::chrono::duration< _Rep, _Period > const &time, task_handler_t const &task) |
| template<class _Rep , class _Period > | |
| TaskScheduler & | ScheduleAt (timepoint_t const &end, std::chrono::duration< _Rep, _Period > const &time, group_t const group, task_handler_t const &task) |
| void | Dispatch (success_t const &callback) |
| Dispatch remaining tasks. | |
Static Private Member Functions | |
| static bool | EmptyValidator () |
| static void | EmptyCallback () |
Private Attributes | |
| std::shared_ptr< TaskScheduler > | self_reference |
| Contains a self reference to track if this object was deleted or not. | |
| timepoint_t | _now |
| The current time point (now) | |
| TaskQueue | _task_holder |
| The Task Queue which contains all task objects. | |
| 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 158 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 116 of file TaskScheduler.h.
|
private |
Definition at line 53 of file TaskScheduler.h.
|
inline |
Definition at line 176 of file TaskScheduler.h.
|
inline |
Definition at line 180 of file TaskScheduler.h.
|
delete |
|
delete |
| TaskScheduler & TaskScheduler::Async | ( | std::function< void()> const & | 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.
Here is the caller graph for this function:| 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.
Here is the call graph for this function:
Here is the caller graph for this function:| TaskScheduler & TaskScheduler::CancelGroup | ( | group_t const | 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.
Here is the call graph for this function:
Here is the caller graph for this function:| 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.
Here is the call graph for this function:
Here is the caller graph for this function:| TaskScheduler & TaskScheduler::ClearValidator | ( | ) |
Clears the validator which is asked if tasks are allowed to be executed.
Definition at line 21 of file TaskScheduler.cpp.
Here is the call graph for this function:
|
inline |
Delays all tasks with the given duration.
Definition at line 273 of file TaskScheduler.h.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Delays all tasks with a random duration between min and max.
Definition at line 285 of file TaskScheduler.h.
Here is the call graph for this function:
|
inline |
Delays all tasks of a group with the given duration.
Definition at line 293 of file TaskScheduler.h.
Here is the call graph for this function:
|
inline |
Delays all tasks of a group with a random duration between min and max.
Definition at line 310 of file TaskScheduler.h.
Here is the call graph for this function:
|
private |
Dispatch remaining tasks.
Definition at line 76 of file TaskScheduler.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlinestaticprivate |
Definition at line 171 of file TaskScheduler.h.
|
inlinestaticprivate |
|
private |
Insert a new task to the enqueued tasks.
Definition at line 70 of file TaskScheduler.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:
|
delete |
|
delete |
|
inline |
Reschedule all tasks with a given duration.
Definition at line 319 of file TaskScheduler.h.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Reschedule all tasks with a random duration between min and max.
Definition at line 332 of file TaskScheduler.h.
Here is the call graph for this function:
|
inline |
Reschedule all tasks of a group with the given duration.
Definition at line 340 of file TaskScheduler.h.
Here is the call graph for this function:
|
inline |
Reschedule all tasks of a group with a random duration between min and max.
Definition at line 358 of file TaskScheduler.h.
Here is the call graph for this function:
|
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.
Here is the call graph for this function:
|
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.
Here is the call graph for this function:
|
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.
Here is the caller graph for this function:| TaskScheduler & TaskScheduler::Update | ( | size_t const | milliseconds, |
| success_t const & | callback = EmptyCallback |
||
| ) |
Update the scheduler with a difftime in ms. Calls the optional callback on successfully finish.
Definition at line 34 of file TaskScheduler.cpp.
Here is the call graph for this function:
|
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 = EmptyCallback | ) |
Update the scheduler to the current time. Calls the optional callback on successfully finish.
Definition at line 27 of file TaskScheduler.cpp.
Here is the call graph for this function:
|
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 162 of file TaskScheduler.h.
|
private |
The current time point (now)
Definition at line 153 of file TaskScheduler.h.
|
private |
Definition at line 164 of file TaskScheduler.h.
|
private |
The Task Queue which contains all task objects.
Definition at line 156 of file TaskScheduler.h.
|
private |
Contains a self reference to track if this object was deleted or not.
Definition at line 150 of file TaskScheduler.h.