11#ifndef UTILS_GP_TIMER_H
12#define UTILS_GP_TIMER_H
16#include <input/gp_types.h>
21#define GP_TIMER_STOP UINT32_MAX
89#define GP_TIMER_DECLARE(name, texpires, tperiod, tid, tcallback, tpriv) \
91 .expires = texpires, \
94 .callback = tcallback, \
168 return queue ? queue->heap.children + 1 : 0;
gp_timer * gp_timer_alloc(uint32_t expires_ms, uint32_t period_ms, const char *id, uint32_t(*callback)(gp_timer *), void *priv)
Allocates a new timer.
void gp_timer_free(gp_timer *self)
Frees timer allocated by gp_timer_alloc().
void gp_timer_queue_dump(const gp_timer *queue)
Prints the structrue of binary heap into stdout, only for debugging.
void gp_timer_queue_ins(gp_timer **queue, uint64_t now, gp_timer *timer)
Inserts timer into the timer priority queue.
void gp_timer_queue_rem(gp_timer **queue, gp_timer *timer)
Removes timer from timer queue.
static int gp_timer_is_running(const gp_timer *timer)
Returns if timer is running.
static unsigned int gp_timer_queue_size(const gp_timer *queue)
Returns size of the queue, i.e. number of timers.
int gp_timer_queue_process(gp_timer **queue, uint64_t now)
Processes queue, all timers with expires <= now are processed.
uint32_t running
Set if timer is inserted into a queue.
uint32_t res_in_callback
Set if timer was rescheduled from callback.
uint32_t(* callback)(struct gp_timer *self)
Timer callback.
void * priv
A user private pointer.
uint32_t in_callback
Set during the run of the timer callback.
void * _priv
Library private pointer. Do not touch!
uint64_t expires
Initial xpiration time, set by user, modified by the queue.
uint32_t period
User variable may be used to store the timer period.
uint32_t free_on_stop
Set if gp_timer_free() was called when timer was running.
const char * id
Timer name showed in debug messages.
void(* stopped)(gp_timer *self)
An optional function to cleanup when timer is stopped.