AIStatefulTask ‐ Asynchronous, Stateful Task Scheduler library.

Threads-like task objects evolving through user-defined states.

Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | List of all members
AITimer Class Reference

Detailed Description

The timer task.

Before calling run(), call set_interval() to pass needed parameters.

When the task finishes it calls the callback, use parameter _1, (success) to check whether or not the task actually timed out or was canceled. The boolean is true when it expired and false if the task was aborted.

Objects of this type can be reused multiple times, see also the documentation of AIStatefulTask.

Typical usage:

AITimer* timer = new AITimer;
timer->set_interval(5.5); // 5.5 seconds time out interval.
timer->run(...); // Start timer and pass callback; see AIStatefulTask.
Definition: AITimer.h:72
void set_interval(threadpool::Timer::Interval interval)
Definition: AITimer.h:107
AITimer(bool debug=false)
Construct an AITimer object.
Definition: AITimer.h:94
void run(Handler default_handler, std::function< void(bool)> cb_function)
Definition: AIStatefulTask.cxx:1192

The default behavior is to call the callback and then delete the AITimer object. One can call run() again from the callback function to get a repeating expiration. You can call run(...) with parameters too, but using run() without parameters will just reuse the old ones (call the same callback).

#include <AITimer.h>

Inheritance diagram for AITimer:
Inheritance graph
Collaboration diagram for AITimer:
Collaboration graph

Public Member Functions

 AITimer (bool debug=false)
 Construct an AITimer object.
void set_interval (threadpool::Timer::Interval interval)
threadpool::Timer::Interval const & get_interval () const
- 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 Attributes

static constexpr state_type state_end = AITimer_expired + 1
 One beyond the largest state of this task.
- 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

enum  timer_state_type { AITimer_start = direct_base_type::state_end , AITimer_expired }
 The different states of the stateful task.
using direct_base_type = AIStatefulTask
 The base class of this task.
- 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...

Protected Member Functions

 ~AITimer () override
 Call finish() (or abort()), not delete.
char const * state_str_impl (state_type run_state) const override
 Implementation of virtual functions of AIStatefulTask. More...
char const * task_name_impl () const override
 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...
void multiplex_impl (state_type run_state) override
 Handle mRunState. More...
void abort_impl () override
 Handle aborting from current bs_run state. More...
- Protected Member Functions inherited from AIStatefulTask
virtual ~AIStatefulTask ()
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 * condition_str_impl (condition_type condition) const
 Called to stringify a condition type for debugging output. More...
virtual void initialize_impl ()
 Called for base state bs_initialize. More...
virtual void finish_impl ()
 Called for base state bs_finish. More...
virtual void force_killed ()
 Called from AIEngine::flush(). 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.
- Static Public Member Functions inherited from AIStatefulTask
static char const * state_str (base_state_type state)

Member Function Documentation

◆ abort_impl()

void AITimer::abort_impl ( )

Handle aborting from current bs_run state.

Reimplemented from AIStatefulTask.

◆ get_interval()

threadpool::Timer::Interval const & AITimer::get_interval ( ) const

Get the expiration interval.

expiration interval in seconds.

◆ multiplex_impl()

void AITimer::multiplex_impl ( state_type  run_state)

Handle mRunState.

Implements AIStatefulTask.

◆ set_interval()

void AITimer::set_interval ( threadpool::Timer::Interval  interval)

Set the interval after which the timer should expire.

intervalAmount of time in seconds before the timer will expire.

Call abort() at any time to stop the timer (and delete the AITimer object).

◆ state_str_impl()

char const * AITimer::state_str_impl ( state_type  run_state) const

Implementation of virtual functions of AIStatefulTask.

Reimplemented from AIStatefulTask.

◆ task_name_impl()

char const * AITimer::task_name_impl ( ) const

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).

Implements AIStatefulTask.

The documentation for this class was generated from the following files: