GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
gp_timer.h File Reference

Timers and timer queue implementation. More...

#include <stdint.h>
#include <utils/gp_types.h>
#include <input/gp_types.h>

Go to the source code of this file.

Data Structures

struct  gp_timer
 A timer. More...
 

Macros

#define GP_TIMER_STOP   UINT32_MAX
 Return this value from the callback to stop a timer.
 

Functions

static int gp_timer_running (gp_timer *timer)
 Returns if timer is running.
 
void gp_timer_queue_dump (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.
 
int gp_timer_queue_process (gp_timer **queue, uint64_t now)
 Processes queue, all timers with expires <= now are processed.
 
static unsigned int gp_timer_queue_size (gp_timer *queue)
 Returns size of the queue, i.e. number of timers.
 

Detailed Description

Timers and timer queue implementation.

Definition in file gp_timer.h.

Function Documentation

◆ gp_timer_queue_dump()

void gp_timer_queue_dump ( gp_timer queue)

Prints the structrue of binary heap into stdout, only for debugging.

Parameters
queueA timer queue.

◆ gp_timer_queue_ins()

void gp_timer_queue_ins ( gp_timer **  queue,
uint64_t  now,
gp_timer timer 
)

Inserts timer into the timer priority queue.

If timer is already running nothing is done. In order to reschedulle a timer it has to be removed from the queue first.

It's safe to call insert from the timer callback.

If timer was removed then inserted from the timer callback the timer is reschedulled at now + timer->expired time and the return value from the callback is discarded.

Parameters
queueA timer queue.
nowA timestamp, usually obtained by calling gp_time_stamp().
timerA timer to insert.

◆ gp_timer_queue_process()

int gp_timer_queue_process ( gp_timer **  queue,
uint64_t  now 
)

Processes queue, all timers with expires <= now are processed.

It's possible to reschedulle a timer with expires set to 0, which will process the timer on the next process call.

Parameters
queueA timer queue.
nowA timestamp, usually obtained by calling gp_time_stamp().
Returns
Number of timers processed.

◆ gp_timer_queue_rem()

void gp_timer_queue_rem ( gp_timer **  queue,
gp_timer timer 
)

Removes timer from timer queue.

It's safe to call remove from the timer callback.

If called from the timer callback the timer is stopped and the return value from the callback is discarded.

Parameters
queueA timer queue.
timerA timer to insert.

◆ gp_timer_queue_size()

static unsigned int gp_timer_queue_size ( gp_timer queue)
inlinestatic

Returns size of the queue, i.e. number of timers.

Parameters
queueA timer queue.
Returns
A Number of timers in the queue.

Definition at line 139 of file gp_timer.h.

◆ gp_timer_running()

static int gp_timer_running ( gp_timer timer)
inlinestatic

Returns if timer is running.

A timer is running if it's inserted into a timer queue.

Parameters
timerA timer.
Returns
Non-zero if timer is running, zero otherwise.

Definition at line 78 of file gp_timer.h.

References gp_timer::running.