src: use namespace prefix osmo_timer*
[osmocom-bb.git] / src / target / firmware / include / comm / timer.h
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
21 #ifndef TIMER_H
22 #define TIMER_H
23
24 #include <sys/time.h>
25
26 #include <osmocom/core/linuxlist.h>
27
28 /**
29  * Timer management:
30  *      - Create a struct osmo_timer_list
31  *      - Fill out timeout and use add_timer or
32  *        use schedule_timer to schedule a timer in
33  *        x seconds and microseconds from now...
34  *      - Use del_timer to remove the timer
35  *
36  *  Internally:
37  *      - We hook into select.c to give a timeval of the
38  *        nearest timer. On already passed timers we give
39  *        it a 0 to immediately fire after the select
40  *      - update_timers will call the callbacks and remove
41  *        the timers.
42  *
43  */
44 struct osmo_timer_list {
45         struct llist_head entry;
46         unsigned long expires;
47
48         unsigned int active  : 1;
49         unsigned int handled : 1;
50         unsigned int in_list : 1;
51
52         void (*cb)(void*);
53         void *data;
54 };
55
56 extern unsigned long volatile jiffies;
57
58 /**
59  * timer management
60  */
61 void add_timer(struct osmo_timer_list *timer);
62 void schedule_timer(struct osmo_timer_list *timer, int miliseconds);
63 void del_timer(struct osmo_timer_list *timer);
64 int timer_pending(struct osmo_timer_list *timer);
65
66
67 /**
68  * internal timer list management
69  */
70 void prepare_timers(void);
71 int update_timers(void);
72 int timer_check(void);
73
74 void timer_init(void);
75
76 #endif