1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21f5a2479SJohn Stultz #ifndef _LINUX_TIMERQUEUE_H 31f5a2479SJohn Stultz #define _LINUX_TIMERQUEUE_H 41f5a2479SJohn Stultz 51f5a2479SJohn Stultz #include <linux/rbtree.h> 61f5a2479SJohn Stultz #include <linux/ktime.h> 71f5a2479SJohn Stultz 81f5a2479SJohn Stultz 91f5a2479SJohn Stultz struct timerqueue_node { 101f5a2479SJohn Stultz struct rb_node node; 111f5a2479SJohn Stultz ktime_t expires; 121f5a2479SJohn Stultz }; 131f5a2479SJohn Stultz 141f5a2479SJohn Stultz struct timerqueue_head { 151f5a2479SJohn Stultz struct rb_root head; 161f5a2479SJohn Stultz struct timerqueue_node *next; 171f5a2479SJohn Stultz }; 181f5a2479SJohn Stultz 191f5a2479SJohn Stultz 20c320642eSThomas Gleixner extern bool timerqueue_add(struct timerqueue_head *head, 211f5a2479SJohn Stultz struct timerqueue_node *node); 22c320642eSThomas Gleixner extern bool timerqueue_del(struct timerqueue_head *head, 231f5a2479SJohn Stultz struct timerqueue_node *node); 241f5a2479SJohn Stultz extern struct timerqueue_node *timerqueue_iterate_next( 251f5a2479SJohn Stultz struct timerqueue_node *node); 261f5a2479SJohn Stultz 2745f74264SThomas Gleixner /** 2825985edcSLucas De Marchi * timerqueue_getnext - Returns the timer with the earliest expiration time 2945f74264SThomas Gleixner * 3045f74264SThomas Gleixner * @head: head of timerqueue 3145f74264SThomas Gleixner * 3245f74264SThomas Gleixner * Returns a pointer to the timer node that has the 3345f74264SThomas Gleixner * earliest expiration time. 3445f74264SThomas Gleixner */ 3545f74264SThomas Gleixner static inline 3645f74264SThomas Gleixner struct timerqueue_node *timerqueue_getnext(struct timerqueue_head *head) 3745f74264SThomas Gleixner { 3845f74264SThomas Gleixner return head->next; 3945f74264SThomas Gleixner } 4045f74264SThomas Gleixner 411f5a2479SJohn Stultz static inline void timerqueue_init(struct timerqueue_node *node) 421f5a2479SJohn Stultz { 434c199a93SMichel Lespinasse RB_CLEAR_NODE(&node->node); 441f5a2479SJohn Stultz } 451f5a2479SJohn Stultz 461f5a2479SJohn Stultz static inline void timerqueue_init_head(struct timerqueue_head *head) 471f5a2479SJohn Stultz { 481f5a2479SJohn Stultz head->head = RB_ROOT; 491f5a2479SJohn Stultz head->next = NULL; 501f5a2479SJohn Stultz } 511f5a2479SJohn Stultz #endif /* _LINUX_TIMERQUEUE_H */ 52