GNU Linux-libre 4.9.309-gnu1
[releases.git] / include / linux / timerqueue.h
1 #ifndef _LINUX_TIMERQUEUE_H
2 #define _LINUX_TIMERQUEUE_H
3
4 #include <linux/rbtree.h>
5 #include <linux/ktime.h>
6
7
8 struct timerqueue_node {
9         struct rb_node node;
10         ktime_t expires;
11 };
12
13 struct timerqueue_head {
14         struct rb_root_cached rb_root;
15 };
16
17
18 extern bool timerqueue_add(struct timerqueue_head *head,
19                            struct timerqueue_node *node);
20 extern bool timerqueue_del(struct timerqueue_head *head,
21                            struct timerqueue_node *node);
22 extern struct timerqueue_node *timerqueue_iterate_next(
23                                                 struct timerqueue_node *node);
24
25 /**
26  * timerqueue_getnext - Returns the timer with the earliest expiration time
27  *
28  * @head: head of timerqueue
29  *
30  * Returns a pointer to the timer node that has the earliest expiration time.
31  */
32 static inline
33 struct timerqueue_node *timerqueue_getnext(struct timerqueue_head *head)
34 {
35         struct rb_node *leftmost = rb_first_cached(&head->rb_root);
36
37         return rb_entry(leftmost, struct timerqueue_node, node);
38 }
39
40 static inline void timerqueue_init(struct timerqueue_node *node)
41 {
42         RB_CLEAR_NODE(&node->node);
43 }
44
45 static inline void timerqueue_init_head(struct timerqueue_head *head)
46 {
47         head->rb_root = RB_ROOT_CACHED;
48 }
49 #endif /* _LINUX_TIMERQUEUE_H */