Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_TIMERQUEUE_H
0003 #define _LINUX_TIMERQUEUE_H
0004 
0005 #include <linux/rbtree.h>
0006 #include <linux/ktime.h>
0007 
0008 
0009 struct timerqueue_node {
0010     struct rb_node node;
0011     ktime_t expires;
0012 };
0013 
0014 struct timerqueue_head {
0015     struct rb_root_cached rb_root;
0016 };
0017 
0018 
0019 extern bool timerqueue_add(struct timerqueue_head *head,
0020                struct timerqueue_node *node);
0021 extern bool timerqueue_del(struct timerqueue_head *head,
0022                struct timerqueue_node *node);
0023 extern struct timerqueue_node *timerqueue_iterate_next(
0024                         struct timerqueue_node *node);
0025 
0026 /**
0027  * timerqueue_getnext - Returns the timer with the earliest expiration time
0028  *
0029  * @head: head of timerqueue
0030  *
0031  * Returns a pointer to the timer node that has the earliest expiration time.
0032  */
0033 static inline
0034 struct timerqueue_node *timerqueue_getnext(struct timerqueue_head *head)
0035 {
0036     struct rb_node *leftmost = rb_first_cached(&head->rb_root);
0037 
0038     return rb_entry(leftmost, struct timerqueue_node, node);
0039 }
0040 
0041 static inline void timerqueue_init(struct timerqueue_node *node)
0042 {
0043     RB_CLEAR_NODE(&node->node);
0044 }
0045 
0046 static inline bool timerqueue_node_queued(struct timerqueue_node *node)
0047 {
0048     return !RB_EMPTY_NODE(&node->node);
0049 }
0050 
0051 static inline bool timerqueue_node_expires(struct timerqueue_node *node)
0052 {
0053     return node->expires;
0054 }
0055 
0056 static inline void timerqueue_init_head(struct timerqueue_head *head)
0057 {
0058     head->rb_root = RB_ROOT_CACHED;
0059 }
0060 #endif /* _LINUX_TIMERQUEUE_H */