AIStatefulTask ‐ Asynchronous, Stateful Task Scheduler library.

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

AITimer.h
Go to the documentation of this file.
1
38#pragma once
39
40#include "AIStatefulTask.h"
41#include "threadpool/Timer.h"
42#include <atomic>
43
71class AITimer : public AIStatefulTask
72{
73 protected:
76
79 AITimer_start = direct_base_type::state_end,
80 AITimer_expired
81 };
82
83 public:
85 static constexpr state_type state_end = AITimer_expired + 1;
86
87 private:
88 std::atomic_bool mHasExpired;
89 threadpool::Timer mTimer;
90 threadpool::Timer::Interval mInterval;
91
92 public:
94 AITimer(CWDEBUG_ONLY(bool debug = false)) :
95#ifdef CWDEBUG
96 AIStatefulTask(debug),
97#endif
98 mHasExpired(false), mTimer([this](){ expired(); }) { DoutEntering(dc::statefultask(mSMDebug), "AITimer::AITimer() [" << (void*)this << "]"); }
99
107 void set_interval(threadpool::Timer::Interval interval) { mInterval = interval; }
108
114 threadpool::Timer::Interval const& get_interval() const { return mInterval; }
115
116 protected:
118 ~AITimer() override { DoutEntering(dc::statefultask(mSMDebug), "AITimer::~AITimer() [" << (void*)this << "]"); /* mFrameTimer.cancel(); */ }
119
121 char const* state_str_impl(state_type run_state) const override;
122 char const* task_name_impl() const override;
123
125 void multiplex_impl(state_type run_state) override;
126
128 void abort_impl() override;
129
130 private:
131 // This is the callback for mFrameTimer.
132 void expired();
133};
Declaration of base class AIStatefulTask.
Definition: AIStatefulTask.h:96
static constexpr state_type state_end
The next state value to use for derived classes.
Definition: AIStatefulTask.h:137
AIStatefulTask(bool debug)
Definition: AIStatefulTask.h:352
uint32_t state_type
The type of run_state.
Definition: AIStatefulTask.h:98
Definition: AITimer.h:72
static constexpr state_type state_end
One beyond the largest state of this task.
Definition: AITimer.h:85
timer_state_type
The different states of the stateful task.
Definition: AITimer.h:78
~AITimer() override
Call finish() (or abort()), not delete.
Definition: AITimer.h:118
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 alw...
Definition: AITimer.cxx:51
char const * state_str_impl(state_type run_state) const override
Implementation of virtual functions of AIStatefulTask.
Definition: AITimer.cxx:41
void abort_impl() override
Handle aborting from current bs_run state.
Definition: AITimer.cxx:80
void set_interval(threadpool::Timer::Interval interval)
Definition: AITimer.h:107
AITimer(bool debug=false)
Construct an AITimer object.
Definition: AITimer.h:94
threadpool::Timer::Interval const & get_interval() const
Definition: AITimer.h:114
void multiplex_impl(state_type run_state) override
Handle mRunState.
Definition: AITimer.cxx:62