EnTT 3.14.0
|
Cooperative scheduler for processes. More...
#include <scheduler.hpp>
Public Types | |
using | allocator_type = Allocator |
Allocator type. | |
using | size_type = std::size_t |
Unsigned integer type. | |
using | delta_type = Delta |
Unsigned integer type. | |
Public Member Functions | |
basic_scheduler () | |
Default constructor. | |
basic_scheduler (const allocator_type &allocator) | |
Constructs a scheduler with a given allocator. | |
basic_scheduler (const basic_scheduler &)=delete | |
Default copy constructor, deleted on purpose. | |
basic_scheduler (basic_scheduler &&other) noexcept | |
Move constructor. | |
basic_scheduler (basic_scheduler &&other, const allocator_type &allocator) | |
Allocator-extended move constructor. | |
~basic_scheduler ()=default | |
Default destructor. | |
basic_scheduler & | operator= (const basic_scheduler &)=delete |
Default copy assignment operator, deleted on purpose. | |
basic_scheduler & | operator= (basic_scheduler &&other) noexcept |
Move assignment operator. | |
void | swap (basic_scheduler &other) noexcept |
Exchanges the contents with those of a given scheduler. | |
constexpr allocator_type | get_allocator () const noexcept |
Returns the associated allocator. | |
size_type | size () const noexcept |
Number of processes currently scheduled. | |
bool | empty () const noexcept |
Returns true if at least a process is currently scheduled. | |
void | clear () |
Discards all scheduled processes. | |
template<typename Proc , typename... Args> | |
basic_scheduler & | attach (Args &&...args) |
Schedules a process for the next tick. | |
template<typename Func > | |
basic_scheduler & | attach (Func &&func) |
Schedules a process for the next tick. | |
template<typename Proc , typename... Args> | |
basic_scheduler & | then (Args &&...args) |
Sets a process as a continuation of the last scheduled process. | |
template<typename Func > | |
basic_scheduler & | then (Func &&func) |
Sets a process as a continuation of the last scheduled process. | |
void | update (const delta_type delta, void *data=nullptr) |
Updates all scheduled processes. | |
void | abort (const bool immediate=false) |
Aborts all scheduled processes. | |
Cooperative scheduler for processes.
A cooperative scheduler runs processes and helps managing their life cycles.
Each process is invoked once per tick. If a process terminates, it's removed automatically from the scheduler and it's never invoked again.
A process can also have a child. In this case, the process is replaced with its child when it terminates if it returns with success. In case of errors, both the process and its child are discarded.
Example of use (pseudocode):
In order to invoke all scheduled processes, call the update
member function passing it the elapsed time to forward to the tasks.
Delta | Type to use to provide elapsed time. |
Allocator | Type of allocator used to manage memory and elements. |
Definition at line 82 of file scheduler.hpp.
using entt::basic_scheduler< Delta, Allocator >::allocator_type = Allocator |
Allocator type.
Definition at line 95 of file scheduler.hpp.
using entt::basic_scheduler< Delta, Allocator >::delta_type = Delta |
Unsigned integer type.
Definition at line 99 of file scheduler.hpp.
using entt::basic_scheduler< Delta, Allocator >::size_type = std::size_t |
Unsigned integer type.
Definition at line 97 of file scheduler.hpp.
|
inline |
Default constructor.
Definition at line 102 of file scheduler.hpp.
|
inlineexplicit |
Constructs a scheduler with a given allocator.
allocator | The allocator to use. |
Definition at line 109 of file scheduler.hpp.
|
inlinenoexcept |
Move constructor.
other | The instance to move from. |
Definition at line 119 of file scheduler.hpp.
|
inline |
Allocator-extended move constructor.
other | The instance to move from. |
allocator | The allocator to use. |
Definition at line 127 of file scheduler.hpp.
Aborts all scheduled processes.
Unless an immediate operation is requested, the abort is scheduled for the next tick. Processes won't be executed anymore in any case.
Once a process is fully aborted and thus finished, it's discarded along with its child, if any.
immediate | Requests an immediate operation. |
Definition at line 352 of file scheduler.hpp.
|
inline |
Schedules a process for the next tick.
Returned value can be used to attach a continuation for the last process. The continutation is scheduled automatically when the process terminates and only if the process returns with success.
Example of use (pseudocode):
Proc | Type of process to schedule. |
Args | Types of arguments to use to initialize the process. |
args | Parameters to use to initialize the process. |
Definition at line 221 of file scheduler.hpp.
|
inline |
Schedules a process for the next tick.
A process can be either a lambda or a functor. The scheduler wraps both of them in a process adaptor internally.
The signature of the function call operator should be equivalent to the following:
Where:
delta
is the elapsed time.data
is an opaque pointer to user data if any, nullptr
otherwise.succeed
is a function to call when a process terminates with success.fail
is a function to call when a process terminates with errors.The signature of the function call operator of both succeed
and fail
is equivalent to the following:
Returned value can be used to attach a continuation for the last process. The continutation is scheduled automatically when the process terminates and only if the process returns with success.
Example of use (pseudocode):
Func | Type of process to schedule. |
func | Either a lambda or a functor to use as a process. |
Definition at line 281 of file scheduler.hpp.
|
inline |
Discards all scheduled processes.
Processes aren't aborted. They are discarded along with their children and never executed again.
Definition at line 191 of file scheduler.hpp.
|
inlinenoexcept |
Returns true if at least a process is currently scheduled.
Definition at line 181 of file scheduler.hpp.
|
inlineconstexprnoexcept |
Returns the associated allocator.
Definition at line 165 of file scheduler.hpp.
|
inlinenoexcept |
Move assignment operator.
other | The instance to move from. |
Definition at line 146 of file scheduler.hpp.
|
delete |
Default copy assignment operator, deleted on purpose.
|
inlinenoexcept |
Number of processes currently scheduled.
Definition at line 173 of file scheduler.hpp.
|
inlinenoexcept |
Exchanges the contents with those of a given scheduler.
other | Scheduler to exchange the content with. |
Definition at line 156 of file scheduler.hpp.
|
inline |
Sets a process as a continuation of the last scheduled process.
Proc | Type of process to use as a continuation. |
Args | Types of arguments to use to initialize the process. |
args | Parameters to use to initialize the process. |
Definition at line 294 of file scheduler.hpp.
|
inline |
Sets a process as a continuation of the last scheduled process.
Func | Type of process to use as a continuation. |
func | Either a lambda or a functor to use as a process. |
Definition at line 310 of file scheduler.hpp.
|
inline |
Updates all scheduled processes.
All scheduled processes are executed in no specific order.
If a process terminates with success, it's replaced with its child, if any. Otherwise, if a process terminates with an error, it's removed along with its child.
delta | Elapsed time. |
data | Optional data. |
Definition at line 326 of file scheduler.hpp.