mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-28 16:56:26 +00:00
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>
This commit is contained in:
parent
5a7987253e
commit
798172b137
@ -14,6 +14,14 @@
|
|||||||
#include <linux/rbtree.h>
|
#include <linux/rbtree.h>
|
||||||
#include <linux/export.h>
|
#include <linux/export.h>
|
||||||
|
|
||||||
|
#define __node_2_tq(_n) \
|
||||||
|
rb_entry((_n), struct timerqueue_node, node)
|
||||||
|
|
||||||
|
static inline bool __timerqueue_less(struct rb_node *a, const struct rb_node *b)
|
||||||
|
{
|
||||||
|
return __node_2_tq(a)->expires < __node_2_tq(b)->expires;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* timerqueue_add - Adds timer to timerqueue.
|
* timerqueue_add - Adds timer to timerqueue.
|
||||||
*
|
*
|
||||||
@ -26,28 +34,10 @@
|
|||||||
*/
|
*/
|
||||||
bool timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node)
|
bool timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node)
|
||||||
{
|
{
|
||||||
struct rb_node **p = &head->rb_root.rb_root.rb_node;
|
|
||||||
struct rb_node *parent = NULL;
|
|
||||||
struct timerqueue_node *ptr;
|
|
||||||
bool leftmost = true;
|
|
||||||
|
|
||||||
/* Make sure we don't add nodes that are already added */
|
/* Make sure we don't add nodes that are already added */
|
||||||
WARN_ON_ONCE(!RB_EMPTY_NODE(&node->node));
|
WARN_ON_ONCE(!RB_EMPTY_NODE(&node->node));
|
||||||
|
|
||||||
while (*p) {
|
return rb_add_cached(&node->node, &head->rb_root, __timerqueue_less);
|
||||||
parent = *p;
|
|
||||||
ptr = rb_entry(parent, struct timerqueue_node, node);
|
|
||||||
if (node->expires < ptr->expires) {
|
|
||||||
p = &(*p)->rb_left;
|
|
||||||
} else {
|
|
||||||
p = &(*p)->rb_right;
|
|
||||||
leftmost = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rb_link_node(&node->node, parent, p);
|
|
||||||
rb_insert_color_cached(&node->node, &head->rb_root, leftmost);
|
|
||||||
|
|
||||||
return leftmost;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(timerqueue_add);
|
EXPORT_SYMBOL_GPL(timerqueue_add);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user