libosmocore  0.9.6-12.20170220git32ee5af8.fc32
Osmocom core library
timer.h
Go to the documentation of this file.
1 /*
2  * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
3  * All Rights Reserved
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  */
20 
29 #pragma once
30 
31 #include <sys/time.h>
32 #include <stdbool.h>
33 
34 #include <osmocom/core/linuxlist.h>
35 #include <osmocom/core/linuxrbtree.h>
36 
55  struct rb_node node;
56  struct llist_head list;
57  struct timeval timeout;
58  unsigned int active : 1;
60  void (*cb)(void*);
61  void *data;
62 };
63 
68 void osmo_timer_add(struct osmo_timer_list *timer);
69 
70 void osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds);
71 
72 void osmo_timer_del(struct osmo_timer_list *timer);
73 
74 int osmo_timer_pending(struct osmo_timer_list *timer);
75 
76 int osmo_timer_remaining(const struct osmo_timer_list *timer,
77  const struct timeval *now,
78  struct timeval *remaining);
79 /*
80  * internal timer list management
81  */
82 struct timeval *osmo_timers_nearest(void);
83 void osmo_timers_prepare(void);
84 int osmo_timers_update(void);
85 int osmo_timers_check(void);
86 
87 int osmo_gettimeofday(struct timeval *tv, struct timezone *tz);
88 
93 extern bool osmo_gettimeofday_override;
94 extern struct timeval osmo_gettimeofday_override_time;
95 void osmo_gettimeofday_override_add(time_t secs, suseconds_t usecs);
96 
osmo_gettimeofday
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_over...
Definition: timer_gettimeofday.c:39
osmo_timer_list
A structure representing a single instance of a timer.
Definition: timer.h:54
osmo_timer_add
void osmo_timer_add(struct osmo_timer_list *timer)
add a new timer to the timer management
Definition: timer.c:71
osmo_timers_update
int osmo_timers_update(void)
fire all timers... and remove them
Definition: timer.c:209
osmo_gettimeofday_override_add
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_tim...
Definition: timer_gettimeofday.c:51
osmo_timer_list::timeout
struct timeval timeout
expiration time
Definition: timer.h:57
osmo_timer_list::data
void * data
user data for callback
Definition: timer.h:61
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
Definition: timer.c:90
osmo_gettimeofday_override
bool osmo_gettimeofday_override
Definition: timer_gettimeofday.c:33
osmo_timers_prepare
void osmo_timers_prepare(void)
Find the nearest time and update nearest_p.
Definition: timer.c:191
osmo_timers_nearest
struct timeval * osmo_timers_nearest(void)
Determine time between now and the nearest timer.
Definition: timer.c:166
llist_head
(double) linked list header structure
Definition: linuxlist.h:47
osmo_timer_list::list
struct llist_head list
internal list header
Definition: timer.h:56
osmo_timer_pending
int osmo_timer_pending(struct osmo_timer_list *timer)
check if given timer is still pending
Definition: timer.c:125
osmo_timer_list::node
struct rb_node node
rb-tree node header
Definition: timer.h:55
osmo_timer_list::cb
void(* cb)(void *)
call-back called at timeout
Definition: timer.h:60
osmo_timer_del
void osmo_timer_del(struct osmo_timer_list *timer)
delete a timer from timer management
Definition: timer.c:107
rb_node
Definition: linuxrbtree.h:99
osmo_timer_list::active
unsigned int active
is it active?
Definition: timer.h:58
osmo_timers_check
int osmo_timers_check(void)
Check how many timers we have in the system.
Definition: timer.c:255
linuxlist.h
Simple doubly linked list implementation.
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
Definition: timer.c:139