Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rbtree, timerqueue: Use rb_add_cached()

Reduce rbtree boiler plate by using the new helpers.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Davidlohr Bueso <dbueso@suse.de>

authored by

Peter Zijlstra and committed by
Ingo Molnar
798172b1 5a798725

+9 -19
+9 -19
lib/timerqueue.c
··· 14 14 #include <linux/rbtree.h> 15 15 #include <linux/export.h> 16 16 17 + #define __node_2_tq(_n) \ 18 + rb_entry((_n), struct timerqueue_node, node) 19 + 20 + static inline bool __timerqueue_less(struct rb_node *a, const struct rb_node *b) 21 + { 22 + return __node_2_tq(a)->expires < __node_2_tq(b)->expires; 23 + } 24 + 17 25 /** 18 26 * timerqueue_add - Adds timer to timerqueue. 19 27 * ··· 34 26 */ 35 27 bool timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node) 36 28 { 37 - struct rb_node **p = &head->rb_root.rb_root.rb_node; 38 - struct rb_node *parent = NULL; 39 - struct timerqueue_node *ptr; 40 - bool leftmost = true; 41 - 42 29 /* Make sure we don't add nodes that are already added */ 43 30 WARN_ON_ONCE(!RB_EMPTY_NODE(&node->node)); 44 31 45 - while (*p) { 46 - parent = *p; 47 - ptr = rb_entry(parent, struct timerqueue_node, node); 48 - if (node->expires < ptr->expires) { 49 - p = &(*p)->rb_left; 50 - } else { 51 - p = &(*p)->rb_right; 52 - leftmost = false; 53 - } 54 - } 55 - rb_link_node(&node->node, parent, p); 56 - rb_insert_color_cached(&node->node, &head->rb_root, leftmost); 57 - 58 - return leftmost; 32 + return rb_add_cached(&node->node, &head->rb_root, __timerqueue_less); 59 33 } 60 34 EXPORT_SYMBOL_GPL(timerqueue_add); 61 35