libosmocore  0.9.6.311-c977
Osmocom core library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
timer.h
Go to the documentation of this file.
1 
3 /*
4  * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22 
40 #pragma once
41 
42 #include <sys/time.h>
43 #include <stdbool.h>
44 
45 #include <osmocom/core/linuxlist.h>
47 
50  struct rb_node node;
51  struct llist_head list;
52  struct timeval timeout;
53  unsigned int active : 1;
55  void (*cb)(void*);
56  void *data;
57 };
58 
59 /*
60  * timer management
61  */
62 
63 void osmo_timer_setup(struct osmo_timer_list *timer, void (*cb)(void *data), void *data);
64 
65 void osmo_timer_add(struct osmo_timer_list *timer);
66 
67 void osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds);
68 
69 void osmo_timer_del(struct osmo_timer_list *timer);
70 
71 int osmo_timer_pending(struct osmo_timer_list *timer);
72 
73 int osmo_timer_remaining(const struct osmo_timer_list *timer,
74  const struct timeval *now,
75  struct timeval *remaining);
76 /*
77  * internal timer list management
78  */
79 struct timeval *osmo_timers_nearest(void);
80 void osmo_timers_prepare(void);
81 int osmo_timers_update(void);
82 int osmo_timers_check(void);
83 
84 int osmo_gettimeofday(struct timeval *tv, struct timezone *tz);
85 
86 /*
87  * timer override
88  */
89 
90 extern bool osmo_gettimeofday_override;
91 extern struct timeval osmo_gettimeofday_override_time;
92 void osmo_gettimeofday_override_add(time_t secs, suseconds_t usecs);
93 
void osmo_timer_del(struct osmo_timer_list *timer)
delete a timer from timer management
Definition: timer.c:118
void osmo_gettimeofday_override_add(time_t secs, suseconds_t usecs)
convenience function to advance the fake time.
Definition: timer_gettimeofday.c:49
struct timeval timeout
expiration time
Definition: timer.h:52
void * data
user data for callback
Definition: timer.h:56
struct llist_head list
internal list header
Definition: timer.h:51
void osmo_timer_add(struct osmo_timer_list *timer)
add a new timer to the timer management
Definition: timer.c:82
void(* cb)(void *)
call-back called at timeout
Definition: timer.h:55
void osmo_timers_prepare(void)
Find the nearest time and update nearest_p.
Definition: timer.c:201
bool osmo_gettimeofday_override
Definition: timer_gettimeofday.c:31
int osmo_timers_update(void)
fire all timers...
Definition: timer.c:219
struct rb_node node
rb-tree node header
Definition: timer.h:50
void osmo_timer_setup(struct osmo_timer_list *timer, void(*cb)(void *data), void *data)
set up timer callback and data
Definition: timer.c:72
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:101
Simple doubly linked list implementation.
(double) linked list header structure
Definition: linuxlist.h:46
struct timeval * osmo_timers_nearest(void)
Determine time between now and the nearest timer.
Definition: timer.c:177
unsigned int active
is it active?
Definition: timer.h:53
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:150
struct timeval osmo_gettimeofday_override_time
Definition: timer_gettimeofday.c:32
int osmo_timers_check(void)
Check how many timers we have in the system.
Definition: timer.c:265
int osmo_gettimeofday(struct timeval *tv, struct timezone *tz)
shim around gettimeofday to be able to set the time manually.
Definition: timer_gettimeofday.c:37
A structure representing a single instance of a timer.
Definition: timer.h:49
int osmo_timer_pending(struct osmo_timer_list *timer)
check if given timer is still pending
Definition: timer.c:136
Definition: linuxrbtree.h:99