libosmocore 0.9.6-23.20170220git32ee5af8.fc42
Osmocom core library
Loading...
Searching...
No Matches
Osmocom timers

Files

file  timer.h
 Osmocom timer handling routines.
 
file  timer_compat.h
 Compatibility header with some helpers.
 
file  timer.c
 
file  timer_gettimeofday.c
 

Data Structures

struct  osmo_timer_list
 A structure representing a single instance of a timer. More...
 

Macros

#define timerisset(tvp)
 
#define timerclear(tvp)
 
#define timercmp(a, b, CMP)
 
#define timeradd(a, b, result)
 
#define timersub(a, b, result)
 

Functions

void osmo_timer_add (struct osmo_timer_list *timer)
 add a new timer to the timer management
 
void osmo_timer_schedule (struct osmo_timer_list *timer, int seconds, int microseconds)
 schedule a timer at a given future relative time
 
void osmo_timer_del (struct osmo_timer_list *timer)
 delete a timer from timer management
 
int osmo_timer_pending (struct osmo_timer_list *timer)
 check if given timer is still pending
 
int osmo_timer_remaining (const struct osmo_timer_list *timer, const struct timeval *now, struct timeval *remaining)
 compute the remaining time of a timer
 
struct timeval * osmo_timers_nearest (void)
 Determine time between now and the nearest timer.
 
void osmo_timers_prepare (void)
 Find the nearest time and update nearest_p.
 
int osmo_timers_update (void)
 fire all timers... and remove them
 
int osmo_timers_check (void)
 Check how many timers we have in the system.
 
int osmo_gettimeofday (struct timeval *tv, struct timezone *tz)
 shim around gettimeofday to be able to set the time manually. To override, set osmo_gettimeofday_override == true and set the desired current time in osmo_gettimeofday_override_time.
 
void osmo_gettimeofday_override_add (time_t secs, suseconds_t usecs)
 convenience function to advance the fake time. Add the given values to osmo_gettimeofday_override_time.
 
static void __add_timer (struct osmo_timer_list *timer)
 
static void update_nearest (struct timeval *cand, struct timeval *current)
 

Variables

bool osmo_gettimeofday_override
 
struct timeval osmo_gettimeofday_override_time
 
static struct timeval nearest
 
static struct timeval * nearest_p
 
static struct rb_root timer_root = RB_ROOT
 
bool osmo_gettimeofday_override = false
 
struct timeval osmo_gettimeofday_override_time = { 23, 424242 }
 

Detailed Description

Macro Definition Documentation

◆ timeradd

#define timeradd ( a,
b,
result )
Value:
do { \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
if ((result)->tv_usec >= 1000000) \
{ \
++(result)->tv_sec; \
(result)->tv_usec -= 1000000; \
} \
} while (0)

◆ timerclear

#define timerclear ( tvp)
Value:
((tvp)->tv_sec = (tvp)->tv_usec = 0)

◆ timercmp

#define timercmp ( a,
b,
CMP )
Value:
(((a)->tv_sec == (b)->tv_sec) ? \
((a)->tv_usec CMP (b)->tv_usec) : \
((a)->tv_sec CMP (b)->tv_sec))

◆ timerisset

#define timerisset ( tvp)
Value:
((tvp)->tv_sec || (tvp)->tv_usec)

◆ timersub

#define timersub ( a,
b,
result )
Value:
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
if ((result)->tv_usec < 0) { \
--(result)->tv_sec; \
(result)->tv_usec += 1000000; \
} \
} while (0)

Function Documentation

◆ osmo_timer_add()

void osmo_timer_add ( struct osmo_timer_list * timer)

add a new timer to the timer management

timer management

Parameters
[in]timerthe timer that should be added

References osmo_timer_list::active, INIT_LLIST_HEAD, osmo_timer_list::list, and osmo_timer_del().

Referenced by osmo_timer_schedule().

◆ osmo_timer_del()

void osmo_timer_del ( struct osmo_timer_list * timer)

delete a timer from timer management

Parameters
[in]timerthe to-be-deleted timer

This function can be used to delete a previously added/scheduled timer from the timer management code.

References osmo_timer_list::active, osmo_timer_list::list, llist_del_init(), llist_empty(), and osmo_timer_list::node.

Referenced by _osmo_fsm_inst_state_chg(), osmo_fsm_inst_free(), osmo_timer_add(), and osmo_timers_update().

◆ osmo_timer_pending()

int osmo_timer_pending ( struct osmo_timer_list * timer)

check if given timer is still pending

Parameters
[in]timerthe to-be-checked timer
Returns
1 if pending, 0 otherwise

This function can be used to determine whether a given timer has alredy expired (returns 0) or is still pending (returns 1)

References osmo_timer_list::active.

◆ osmo_timer_remaining()

int osmo_timer_remaining ( const struct osmo_timer_list * timer,
const struct timeval * now,
struct timeval * remaining )

compute the remaining time of a timer

Parameters
[in]timerthe to-be-checked timer
[in]nowthe current time (NULL if not known)
[out]remainingremaining time until timer fires
Returns
0 if timer has not expired yet, -1 if it has

This function can be used to determine the amount of time remaining until the expiration of the timer.

References osmo_gettimeofday(), and osmo_timer_list::timeout.

◆ osmo_timer_schedule()

void osmo_timer_schedule ( struct osmo_timer_list * timer,
int seconds,
int microseconds )

schedule a timer at a given future relative time

Parameters
[in]timerthe to-be-added timer
[in]secondsnumber of seconds from now
[in]microsecondsnumber of microseconds from now

This function can be used to (re-)schedule a given timer at a specified number of seconds+microseconds in the future. It will internally add it to the timer management data structures, thus osmo_timer_add() is automatically called.

References osmo_gettimeofday(), osmo_timer_add(), and osmo_timer_list::timeout.

Referenced by _osmo_fsm_inst_state_chg(), and rate_ctr_init().

◆ osmo_timers_check()

int osmo_timers_check ( void )

Check how many timers we have in the system.

Returns
number of osmo_timer_list registered

◆ osmo_timers_nearest()

struct timeval * osmo_timers_nearest ( void )

Determine time between now and the nearest timer.

Returns
pointer to timeval of nearest timer, NULL if there is none

if we have a nearest time return the delta between the current time and the time of the nearest timer. If the nearest timer timed out return NULL and then we will dispatch everything after the select

Referenced by osmo_select_main().

Variable Documentation

◆ osmo_gettimeofday_override [1/2]

bool osmo_gettimeofday_override
extern

timer override

Referenced by osmo_gettimeofday().

◆ osmo_gettimeofday_override [2/2]

bool osmo_gettimeofday_override = false

timer override

Referenced by osmo_gettimeofday().