blob: fee888bfd9719896d4c2fcbed4d70469baa9a23d [file] [log] [blame]
Holger Freyther5f755982008-12-27 09:42:59 +00001/*
Harald Welteb8f04ea2009-01-02 23:57:22 +00002 * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Freyther5f755982008-12-27 09:42:59 +00003 * 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 "linuxlist.h"
27
28/**
29 * Timer management:
30 * - Create a struct 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 */
44struct timer_list {
45 struct llist_head entry;
46 struct timeval timeout;
Holger Hans Peter Freyther251aa912009-10-27 10:42:28 +010047 unsigned int active : 1;
48 unsigned int handled : 1;
49 unsigned int in_list : 1;
Holger Freyther5f755982008-12-27 09:42:59 +000050
51 void (*cb)(void*);
52 void *data;
53};
54
55/**
56 * timer management
57 */
Harald Welteff117a82009-05-23 05:22:08 +000058void bsc_add_timer(struct timer_list *timer);
59void bsc_schedule_timer(struct timer_list *timer, int seconds, int microseconds);
60void bsc_del_timer(struct timer_list *timer);
61int bsc_timer_pending(struct timer_list *timer);
Holger Freyther5f755982008-12-27 09:42:59 +000062
63
64/**
65 * internal timer list management
66 */
Harald Welteff117a82009-05-23 05:22:08 +000067struct timeval *bsc_nearest_timer();
68void bsc_prepare_timers();
69int bsc_update_timers();
Holger Hans Peter Freyther65fb0fd2009-10-22 15:39:37 +020070int bsc_timer_check(void);
Holger Freyther5f755982008-12-27 09:42:59 +000071
72#endif