48 long long new_period =
timeout();
55 else if (new_period ==
DELETE)
59 else if (new_period > 0)
65ActiveTimers::~ActiveTimers()
89 Timer *current_timer =
static_cast<Timer *
>(*last);
91 bool found_timer =
false;
92 while (current_timer && current_timer->
when_ <= now)
96 *last = current_timer->
next;
97 current_timer->
next =
nullptr;
104 current_timer =
static_cast<Timer *
>(*last);
111 else if (current_timer)
113 long long ret = current_timer->
when_ - now;
128 Timer *current_timer =
static_cast<Timer *
>(*last);
129 return (current_timer ==
nullptr);
144 Timer *current_timer =
static_cast<Timer *
>(*last);
145 while (current_timer && current_timer->
when_ <= timer->
when_)
147 last = ¤t_timer->
next;
148 current_timer =
static_cast<Timer *
>(*last);
151 timer->
next = current_timer;
164 while (*last && *last != timer)
166 last = &((*last)->next);
170 timer->
next =
nullptr;
ExecutorBase * executor_
Parent.
void run() override
Callback from the executor.
void remove_timer(::Timer *timer)
Deletes an already scheduled but not yet expired timer.
void remove_locked(::Timer *timer)
Removes a timer from the active list.
void insert_locked(::Timer *timer)
Inserts a timer into the active list.
std::atomic_uint_least8_t isPending_
1 if we in the executor's queue.
void schedule_timer(::Timer *timer)
Adds a new timer to the active timer list.
long long get_next_timeout()
Tell when the first timer will expire.
void update_timer(::Timer *timer)
Updates the expiration time of an already scheduled timer.
void notify() override
Notification callback from the timer.
OSMutex lock_
Protects the timer list.
QMember activeTimers_
List of timers that are scheduled.
virtual void add(Executable *action, unsigned priority=UINT_MAX)=0
Send a message to this Executor's queue.
Class to allow convenient locking and unlocking of mutexes in a C context.
static long long get_monotonic()
Get the monotonic time since the system started.
Essentially a "next" pointer container.
QMember * next
pointer to the next member in the queue
A timer that can schedule itself to run on an executor at specified times in the future.
@ RESTART
Restart the timer with existing period.
@ DELETE
delete the timer, use with extreme caution
unsigned isActive_
true when the timer is in the active timers list
void start(long long period=-1)
Starts a timer.
void run() override
Callback from the executor when this timer is scheduled.
ActiveTimers * activeTimers_
Points to the executor's timer structure.
long long period_
period in nanoseconds for timer
long long when_
when in nanoseconds timer should expire
unsigned isExpired_
True when the timer is in the pending executables list of the Executor.
virtual long long timeout()=0
Clients of timer should override this function.
unsigned priority_
what priority to schedule this timer at
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define SEC_TO_NSEC(_sec)
Convert a second value to a nanosecond value.