Skip to content

Commit 1ca7b86

Browse files
committed
rtmutex: Simplify remove_waiter()
Exit right away, when the removed waiter was not the top priority waiter on the lock. Get rid of the extra indent level. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Steven Rostedt <rostedt@goodmis.org> Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com>
1 parent 3eb65ae commit 1ca7b86

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

‎kernel/locking/rtmutex.c‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -917,39 +917,41 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
917917
static void remove_waiter(struct rt_mutex *lock,
918918
struct rt_mutex_waiter *waiter)
919919
{
920-
int first = (waiter == rt_mutex_top_waiter(lock));
920+
bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
921921
struct task_struct *owner = rt_mutex_owner(lock);
922-
struct rt_mutex *next_lock = NULL;
922+
struct rt_mutex *next_lock;
923923
unsigned long flags;
924924

925925
raw_spin_lock_irqsave(&current->pi_lock, flags);
926926
rt_mutex_dequeue(lock, waiter);
927927
current->pi_blocked_on = NULL;
928928
raw_spin_unlock_irqrestore(&current->pi_lock, flags);
929929

930-
if (!owner)
930+
/*
931+
* Only update priority if the waiter was the highest priority
932+
* waiter of the lock and there is an owner to update.
933+
*/
934+
if (!owner || !is_top_waiter)
931935
return;
932936

933-
if (first) {
934-
935-
raw_spin_lock_irqsave(&owner->pi_lock, flags);
937+
raw_spin_lock_irqsave(&owner->pi_lock, flags);
936938

937-
rt_mutex_dequeue_pi(owner, waiter);
939+
rt_mutex_dequeue_pi(owner, waiter);
938940

939-
if (rt_mutex_has_waiters(lock)) {
940-
struct rt_mutex_waiter *next;
941+
if (rt_mutex_has_waiters(lock))
942+
rt_mutex_enqueue_pi(owner, rt_mutex_top_waiter(lock));
941943

942-
next = rt_mutex_top_waiter(lock);
943-
rt_mutex_enqueue_pi(owner, next);
944-
}
945-
__rt_mutex_adjust_prio(owner);
944+
__rt_mutex_adjust_prio(owner);
946945

947-
/* Store the lock on which owner is blocked or NULL */
948-
next_lock = task_blocked_on_lock(owner);
946+
/* Store the lock on which owner is blocked or NULL */
947+
next_lock = task_blocked_on_lock(owner);
949948

950-
raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
951-
}
949+
raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
952950

951+
/*
952+
* Don't walk the chain, if the owner task is not blocked
953+
* itself.
954+
*/
953955
if (!next_lock)
954956
return;
955957

0 commit comments

Comments
 (0)