AIStatefulTask ‐ Asynchronous, Stateful Task Scheduler library. Threads-like task objects evolving through user-defined states. |
Every stateful task is (indirectly) derived from AIStatefulTask.
For example:
Protected Member Functions | |
char const * | condition_str_impl (condition_type run_state) const override |
char const * | state_str_impl (state_type run_state) const override |
void | initialize_impl () override |
void | multiplex_impl (state_type run_state) override |
void | abort_impl () override |
void | finish_impl () override |
void | force_killed () override |
Protected Member Functions inherited from AIStatefulTask | |
virtual | ~AIStatefulTask () |
Destructor. | |
void | set_state (state_type new_state) |
void | wait (condition_type conditions) |
void | wait_until (AIWaitConditionFunc const &wait_condition, condition_type conditions) |
void | wait_until (AIWaitConditionFunc const &wait_condition, condition_type conditions, state_type new_state) |
void | finish () |
utils::FuzzyBool | is_self_locked (AIStatefulTaskMutex const &stateful_task_mutex, AIStatefulTaskMutexNode const *handle) |
void | yield () |
void | target (Handler handler) |
void | yield (Handler handler) |
void | yield_frame (AIEngine *engine, unsigned int frames) |
void | yield_ms (AIEngine *engine, unsigned int ms) |
bool | yield_if_not (Handler handler) |
virtual char const * | task_name_impl () const =0 |
This can be used to get a human readable name of the most-derived class. It must be guaranteed to always return the same pointer value so it can be used with Tracy (for example). More... | |
Additional Inherited Members | |
Public Types inherited from AIStatefulTask | |
enum | on_abort_st { abort_parent , signal_parent , do_nothing } |
What to do when a child task is aborted. More... | |
using | state_type = uint32_t |
The type of run_state. | |
using | condition_type = uint32_t |
The type of the skip_wait and idle bit masks. | |
Public Member Functions inherited from AIStatefulTask | |
Conditions | print_conditions (condition_type conditions) |
AIStatefulTask (bool debug) | |
void | run (Handler default_handler, std::function< void(bool)> cb_function) |
void | run (std::function< void(bool)> cb_function) |
The same as above but use the immediate Handler. | |
void | run (Handler default_handler, AIStatefulTask *parent, condition_type condition, on_abort_st on_abort=abort_parent) |
void | run (AIStatefulTask *parent, condition_type condition, on_abort_st on_abort=abort_parent) |
void | run (Handler default_handler=Handler::immediate) |
void | kill () |
void | abort () |
bool | signal (condition_type condition) |
bool | running () const |
bool | waiting () const |
bool | waiting_or_aborting () const |
bool | active (Handler handler) const |
bool | is_immediate () const |
bool | finished () const |
bool | aborted () const |
bool | executing () const |
duration_type | getDuration () const |
char const * | task_name () const |
Static Public Member Functions inherited from AIStatefulTask | |
static char const * | state_str (base_state_type state) |
Static Public Attributes inherited from AIStatefulTask | |
static constexpr condition_type | slow_down_condition = 0x40000000 |
static constexpr condition_type | thread_pool_full_condition = 0x80000000 |
static constexpr condition_type | AND_conditions_mask = 0xf0000000 |
static constexpr condition_type | OR_conditions_mask = 0x0fffffff |
static constexpr state_type | state_end = bs_killed + 1 |
The next state value to use for derived classes. | |
Protected Types inherited from AIStatefulTask | |
enum | base_state_type { bs_reset , bs_initialize , bs_multiplex , bs_abort , bs_finish , bs_callback , bs_killed } |
The type of mState . More... | |
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
Stringify a condition, for debugging output.
condition | A user defined condition. |
This is a virtual function of the base class AIStatefulTask and should be overridden by every derived class.
Example implementation:
Reimplemented from AIStatefulTask.
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
Handle being force killed.
This member function is called when a task is running in an AIEngine and that engine is flushed (by calling AIEngine::flush()). The result is that the task just stops running cold. Neither abort_impl() nor finish_impl() is called: it just stops getting any CPU cycles and should be destructed shortly.
You probably will never to override this function. In fact, it will never be called unless you call AIEngine::flush() yourself and its main purpose is to avoid an assert in the destructor of the tasks (because otherwise their internal state would show they are still running which is an error otherwise).
Example implementation:
Reimplemented from AIStatefulTask.
|
overrideprotectedvirtual |
Return a human readable name for the most derived class.
This is a virtual function of the base class AIStatefulTask and must be overridden by every derived class.
Example implementation:
Reimplemented from AIStatefulTask.
|
overrideprotectedvirtual |
The main implementation of the task. Run the task.
run_state | The current user defined state that the task is in. |
Example implementation:
Implements AIStatefulTask.
|
overrideprotectedvirtual |
Stringify a run state, for debugging output.
run_state | A user defined state. |
This is a virtual function of the base class AIStatefulTask and must be overridden by every derived class.
Example implementation:
Reimplemented from AIStatefulTask.