diff options
author | Holger Freyther <zecke@selfish.org> | 2008-12-27 09:42:59 +0000 |
---|---|---|
committer | Holger Freyther <zecke@selfish.org> | 2008-12-27 09:42:59 +0000 |
commit | 5f75598c2804380ca07a5d52a411b5b64ba57fc3 (patch) | |
tree | 668e806888d49e1f32b026b5f7b83bb8c6e733d4 /include | |
parent | 5677ae35ba3e4b617c590b46f0f224a15f924e5b (diff) |
Introduce a simple timer API....
One can use add_timer or schedule_timer to add a timer. After
the timeout time has been reached the callback will be called.
One can call add_time/schedule_timer and del_timer from within
the callback.
Diffstat (limited to 'include')
-rw-r--r-- | include/openbsc/timer.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/include/openbsc/timer.h b/include/openbsc/timer.h new file mode 100644 index 000000000..e8dc91a84 --- /dev/null +++ b/include/openbsc/timer.h @@ -0,0 +1,70 @@ +/* + * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org> + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef TIMER_H +#define TIMER_H + +#include <sys/time.h> + +#include "linuxlist.h" + +/** + * Timer management: + * - Create a struct timer_list + * - Fill out timeout and use add_timer or + * use schedule_timer to schedule a timer in + * x seconds and microseconds from now... + * - Use del_timer to remove the timer + * + * Internally: + * - We hook into select.c to give a timeval of the + * nearest timer. On already passed timers we give + * it a 0 to immediately fire after the select + * - update_timers will call the callbacks and remove + * the timers. + * + */ +struct timer_list { + struct llist_head entry; + struct timeval timeout; + int active : 1; + int handled : 1; + + void (*cb)(void*); + void *data; +}; + +/** + * timer management + */ +void add_timer(struct timer_list *timer); +void schedule_timer(struct timer_list *timer, int seconds, int microseconds); +void del_timer(struct timer_list *timer); +int timer_pending(struct timer_list *timer); + + +/** + * internal timer list management + */ +struct timeval *nearest_timer(); +void prepare_timers(); +void update_timers(); + +#endif |