remote: close file on usteer_init_local_id fread fail
[project/usteer.git] / timeout.h
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
14 *
15 * Copyright (C) 2020 embedd.ch
16 * Copyright (C) 2020 Felix Fietkau <nbd@nbd.name>
17 * Copyright (C) 2020 John Crispin <john@phrozen.org>
18 */
19
20 #ifndef __APMGR_TIMEOUT_H
21 #define __APMGR_TIMEOUT_H
22
23 #include <libubox/avl.h>
24 #include <libubox/uloop.h>
25
26 struct usteer_timeout {
27 struct avl_node node;
28 };
29
30 struct usteer_timeout_queue {
31 struct avl_tree tree;
32 struct uloop_timeout timeout;
33 void (*cb)(struct usteer_timeout_queue *q, struct usteer_timeout *t);
34 };
35
36 static inline bool
37 usteer_timeout_isset(struct usteer_timeout *t)
38 {
39 return t->node.list.prev != NULL;
40 }
41
42 void usteer_timeout_init(struct usteer_timeout_queue *q);
43 void usteer_timeout_set(struct usteer_timeout_queue *q, struct usteer_timeout *t,
44 int msecs);
45 void usteer_timeout_cancel(struct usteer_timeout_queue *q,
46 struct usteer_timeout *t);
47 void usteer_timeout_flush(struct usteer_timeout_queue *q);
48
49 #endif