Commit 5a798725 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

rbtree, rtmutex: Use rb_add_cached()

Reduce rbtree boiler plate by using the new helpers.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Acked-by: default avatarDavidlohr Bueso <dbueso@suse.de>
parent a905e84e
...@@ -267,27 +267,18 @@ rt_mutex_waiter_equal(struct rt_mutex_waiter *left, ...@@ -267,27 +267,18 @@ rt_mutex_waiter_equal(struct rt_mutex_waiter *left,
return 1; return 1;
} }
#define __node_2_waiter(node) \
rb_entry((node), struct rt_mutex_waiter, tree_entry)
static inline bool __waiter_less(struct rb_node *a, const struct rb_node *b)
{
return rt_mutex_waiter_less(__node_2_waiter(a), __node_2_waiter(b));
}
static void static void
rt_mutex_enqueue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter) rt_mutex_enqueue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter)
{ {
struct rb_node **link = &lock->waiters.rb_root.rb_node; rb_add_cached(&waiter->tree_entry, &lock->waiters, __waiter_less);
struct rb_node *parent = NULL;
struct rt_mutex_waiter *entry;
bool leftmost = true;
while (*link) {
parent = *link;
entry = rb_entry(parent, struct rt_mutex_waiter, tree_entry);
if (rt_mutex_waiter_less(waiter, entry)) {
link = &parent->rb_left;
} else {
link = &parent->rb_right;
leftmost = false;
}
}
rb_link_node(&waiter->tree_entry, parent, link);
rb_insert_color_cached(&waiter->tree_entry, &lock->waiters, leftmost);
} }
static void static void
...@@ -300,27 +291,18 @@ rt_mutex_dequeue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter) ...@@ -300,27 +291,18 @@ rt_mutex_dequeue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter)
RB_CLEAR_NODE(&waiter->tree_entry); RB_CLEAR_NODE(&waiter->tree_entry);
} }
#define __node_2_pi_waiter(node) \
rb_entry((node), struct rt_mutex_waiter, pi_tree_entry)
static inline bool __pi_waiter_less(struct rb_node *a, const struct rb_node *b)
{
return rt_mutex_waiter_less(__node_2_pi_waiter(a), __node_2_pi_waiter(b));
}
static void static void
rt_mutex_enqueue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter) rt_mutex_enqueue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter)
{ {
struct rb_node **link = &task->pi_waiters.rb_root.rb_node; rb_add_cached(&waiter->pi_tree_entry, &task->pi_waiters, __pi_waiter_less);
struct rb_node *parent = NULL;
struct rt_mutex_waiter *entry;
bool leftmost = true;
while (*link) {
parent = *link;
entry = rb_entry(parent, struct rt_mutex_waiter, pi_tree_entry);
if (rt_mutex_waiter_less(waiter, entry)) {
link = &parent->rb_left;
} else {
link = &parent->rb_right;
leftmost = false;
}
}
rb_link_node(&waiter->pi_tree_entry, parent, link);
rb_insert_color_cached(&waiter->pi_tree_entry, &task->pi_waiters, leftmost);
} }
static void static void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment