TrinityCore
|
#include <TaskScheduler.h>
Public Member Functions | |
TaskContext () | |
TaskContext (TaskScheduler::TaskContainer &&task, std::weak_ptr< TaskScheduler > &&owner) | |
TaskContext (TaskContext const &right) | |
TaskContext (TaskContext &&right) noexcept | |
TaskContext & | operator= (TaskContext const &right) |
TaskContext & | operator= (TaskContext &&right) noexcept |
~TaskContext ()=default | |
bool | IsExpired () const |
Returns true if the owner was deallocated and this context has expired. More... | |
bool | IsInGroup (TaskScheduler::group_t const group) const |
Returns true if the event is in the given group. More... | |
TaskContext & | SetGroup (TaskScheduler::group_t const group) |
Sets the event in the given group. More... | |
TaskContext & | ClearGroup () |
Removes the group from the event. More... | |
TaskScheduler::repeated_t | GetRepeatCounter () const |
Returns the repeat counter which increases every time the task is repeated. More... | |
template<class Rep , class Period > | |
TaskContext & | Repeat (std::chrono::duration< Rep, Period > duration) |
TaskContext & | Repeat () |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskContext & | Repeat (std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max) |
TaskContext & | Async (std::function< void()> const &callable) |
template<class Rep , class Period > | |
TaskContext & | Schedule (std::chrono::duration< Rep, Period > time, TaskScheduler::task_handler_t task) |
template<class Rep , class Period > | |
TaskContext & | Schedule (std::chrono::duration< Rep, Period > time, TaskScheduler::group_t const group, TaskScheduler::task_handler_t task) |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskContext & | Schedule (std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max, TaskScheduler::task_handler_t task) |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskContext & | Schedule (std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max, TaskScheduler::group_t const group, TaskScheduler::task_handler_t task) |
TaskContext & | CancelAll () |
Cancels all tasks from within the context. More... | |
TaskContext & | CancelGroup (TaskScheduler::group_t const group) |
Cancel all tasks of a single group from within the context. More... | |
TaskContext & | CancelGroupsOf (std::vector< TaskScheduler::group_t > const &groups) |
template<class Rep , class Period > | |
TaskContext & | DelayAll (std::chrono::duration< Rep, Period > duration) |
Delays all tasks with the given duration from within the context. More... | |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskContext & | DelayAll (std::chrono::duration< RepLeft, PeriodLeft > min, std::chrono::duration< RepRight, PeriodRight > max) |
Delays all tasks with a random duration between min and max from within the context. More... | |
template<class Rep , class Period > | |
TaskContext & | DelayGroup (TaskScheduler::group_t const group, std::chrono::duration< Rep, Period > duration) |
Delays all tasks of a group with the given duration from within the context. More... | |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskContext & | DelayGroup (TaskScheduler::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 from within the context. More... | |
template<class Rep , class Period > | |
TaskContext & | RescheduleAll (std::chrono::duration< Rep, Period > duration) |
Reschedule all tasks with the given duration. More... | |
template<class RepLeft , class PeriodLeft , class RepRight , class PeriodRight > | |
TaskContext & | 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 > | |
TaskContext & | RescheduleGroup (TaskScheduler::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 > | |
TaskContext & | RescheduleGroup (TaskScheduler::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 Member Functions | |
TaskContext & | Dispatch (std::function< TaskScheduler &(TaskScheduler &)> const &apply) |
Dispatches an action safe on the TaskScheduler. More... | |
void | AssertOnConsumed () const |
Asserts if the task was consumed already. More... | |
void | Invoke () |
Invokes the associated hook of the task. More... | |
Private Attributes | |
TaskScheduler::TaskContainer | _task |
Associated task. More... | |
std::weak_ptr< TaskScheduler > | _owner |
Owner. More... | |
std::shared_ptr< bool > | _consumed |
Marks the task as consumed. More... | |
Friends | |
class | TaskScheduler |
Definition at line 391 of file TaskScheduler.h.
|
inline |
Definition at line 409 of file TaskScheduler.h.
|
inlineexplicit |
Definition at line 413 of file TaskScheduler.h.
|
inline |
Definition at line 417 of file TaskScheduler.h.
|
inlinenoexcept |
Definition at line 421 of file TaskScheduler.h.
|
default |
|
private |
Asserts if the task was consumed already.
Definition at line 230 of file TaskScheduler.cpp.
TaskContext & TaskContext::Async | ( | std::function< void()> const & | callable | ) |
Schedule a callable function that is executed at the next update tick from within the context. Its safe to modify the TaskScheduler from within the callable.
Definition at line 201 of file TaskScheduler.cpp.
TaskContext & TaskContext::CancelAll | ( | ) |
Cancels all tasks from within the context.
Definition at line 209 of file TaskScheduler.cpp.
TaskContext & TaskContext::CancelGroup | ( | TaskScheduler::group_t const | group | ) |
Cancel all tasks of a single group from within the context.
Definition at line 214 of file TaskScheduler.cpp.
TaskContext & TaskContext::CancelGroupsOf | ( | std::vector< TaskScheduler::group_t > const & | groups | ) |
Cancels all groups in the given std::vector from within the context. Hint: Use std::initializer_list for this: "{1, 2, 3, 4}"
Definition at line 222 of file TaskScheduler.cpp.
TaskContext & TaskContext::ClearGroup | ( | ) |
Removes the group from the event.
Definition at line 190 of file TaskScheduler.cpp.
|
inline |
Delays all tasks with the given duration from within the context.
Definition at line 573 of file TaskScheduler.h.
|
inline |
Delays all tasks with a random duration between min and max from within the context.
Definition at line 583 of file TaskScheduler.h.
|
inline |
Delays all tasks of a group with the given duration from within the context.
Definition at line 591 of file TaskScheduler.h.
|
inline |
Delays all tasks of a group with a random duration between min and max from within the context.
Definition at line 601 of file TaskScheduler.h.
|
private |
Dispatches an action safe on the TaskScheduler.
Definition at line 166 of file TaskScheduler.cpp.
TaskScheduler::repeated_t TaskContext::GetRepeatCounter | ( | ) | const |
Returns the repeat counter which increases every time the task is repeated.
Definition at line 196 of file TaskScheduler.cpp.
|
private |
Invokes the associated hook of the task.
Definition at line 237 of file TaskScheduler.cpp.
bool TaskContext::IsExpired | ( | ) | const |
Returns true if the owner was deallocated and this context has expired.
Definition at line 174 of file TaskScheduler.cpp.
bool TaskContext::IsInGroup | ( | TaskScheduler::group_t const | group | ) | const |
Returns true if the event is in the given group.
Definition at line 179 of file TaskScheduler.cpp.
|
inlinenoexcept |
Definition at line 437 of file TaskScheduler.h.
|
inline |
Definition at line 425 of file TaskScheduler.h.
|
inline |
Repeats the event with the same duration. This will consume the task context, its not possible to repeat the task again from the same task context!
Definition at line 488 of file TaskScheduler.h.
|
inline |
Repeats the event and sets a new duration. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context!
Definition at line 470 of file TaskScheduler.h.
|
inline |
Repeats the event and set a new duration that is randomized between min and max. std::chrono::seconds(5) for example. This will consume the task context, its not possible to repeat the task again from the same task context!
Definition at line 498 of file TaskScheduler.h.
|
inline |
Reschedule all tasks with the given duration.
Definition at line 610 of file TaskScheduler.h.
|
inline |
Reschedule all tasks with a random duration between min and max.
Definition at line 620 of file TaskScheduler.h.
|
inline |
Reschedule all tasks of a group with the given duration.
Definition at line 628 of file TaskScheduler.h.
|
inline |
Reschedule all tasks of a group with a random duration between min and max.
Definition at line 638 of file TaskScheduler.h.
|
inline |
Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.
Definition at line 528 of file TaskScheduler.h.
|
inline |
Schedule an event with a fixed rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.
Definition at line 513 of file TaskScheduler.h.
|
inline |
Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.
Definition at line 554 of file TaskScheduler.h.
|
inline |
Schedule an event with a randomized rate between min and max rate from within the context. Its possible that the new event is executed immediately! Use TaskScheduler::Async to create a task which will be called at the next update tick.
Definition at line 543 of file TaskScheduler.h.
TaskContext & TaskContext::SetGroup | ( | TaskScheduler::group_t const | group | ) |
Sets the event in the given group.
Definition at line 184 of file TaskScheduler.cpp.
|
friend |
Definition at line 393 of file TaskScheduler.h.
|
private |
Marks the task as consumed.
Definition at line 402 of file TaskScheduler.h.
|
private |
Owner.
Definition at line 399 of file TaskScheduler.h.
|
private |
Associated task.
Definition at line 396 of file TaskScheduler.h.