mutex.c (5bbd7e644378334700889fb762d5893985a7311f) mutex.c (a40ca56577f628eb3f7af22b484e95edfdd047a2)
1/*
2 * kernel/locking/mutex.c
3 *
4 * Mutexes: blocking mutual exclusion locks
5 *
6 * Started by Ingo Molnar:
7 *
8 * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>

--- 573 unchanged lines hidden (view full) ---

582__mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
583 struct lockdep_map *nest_lock, unsigned long ip,
584 struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
585{
586 struct task_struct *task = current;
587 struct mutex_waiter waiter;
588 unsigned long flags;
589 bool first = false;
1/*
2 * kernel/locking/mutex.c
3 *
4 * Mutexes: blocking mutual exclusion locks
5 *
6 * Started by Ingo Molnar:
7 *
8 * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>

--- 573 unchanged lines hidden (view full) ---

582__mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
583 struct lockdep_map *nest_lock, unsigned long ip,
584 struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
585{
586 struct task_struct *task = current;
587 struct mutex_waiter waiter;
588 unsigned long flags;
589 bool first = false;
590 struct ww_mutex *ww;
590 int ret;
591
592 if (use_ww_ctx) {
591 int ret;
592
593 if (use_ww_ctx) {
593 struct ww_mutex *ww = container_of(lock, struct ww_mutex, base);
594 ww = container_of(lock, struct ww_mutex, base);
594 if (unlikely(ww_ctx == READ_ONCE(ww->ctx)))
595 return -EALREADY;
596 }
597
598 preempt_disable();
599 mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip);
600
601 if (__mutex_trylock(lock, false) ||
602 mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx)) {
603 /* got the lock, yay! */
604 lock_acquired(&lock->dep_map, ip);
595 if (unlikely(ww_ctx == READ_ONCE(ww->ctx)))
596 return -EALREADY;
597 }
598
599 preempt_disable();
600 mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip);
601
602 if (__mutex_trylock(lock, false) ||
603 mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx)) {
604 /* got the lock, yay! */
605 lock_acquired(&lock->dep_map, ip);
605 if (use_ww_ctx) {
606 struct ww_mutex *ww;
607 ww = container_of(lock, struct ww_mutex, base);
608
606 if (use_ww_ctx)
609 ww_mutex_set_context_fastpath(ww, ww_ctx);
607 ww_mutex_set_context_fastpath(ww, ww_ctx);
610 }
611 preempt_enable();
612 return 0;
613 }
614
615 spin_lock_mutex(&lock->wait_lock, flags);
616 /*
617 * After waiting to acquire the wait_lock, try again.
618 */

--- 67 unchanged lines hidden (view full) ---

686 __mutex_clear_flag(lock, MUTEX_FLAGS);
687
688 debug_mutex_free_waiter(&waiter);
689
690skip_wait:
691 /* got the lock - cleanup and rejoice! */
692 lock_acquired(&lock->dep_map, ip);
693
608 preempt_enable();
609 return 0;
610 }
611
612 spin_lock_mutex(&lock->wait_lock, flags);
613 /*
614 * After waiting to acquire the wait_lock, try again.
615 */

--- 67 unchanged lines hidden (view full) ---

683 __mutex_clear_flag(lock, MUTEX_FLAGS);
684
685 debug_mutex_free_waiter(&waiter);
686
687skip_wait:
688 /* got the lock - cleanup and rejoice! */
689 lock_acquired(&lock->dep_map, ip);
690
694 if (use_ww_ctx) {
695 struct ww_mutex *ww = container_of(lock, struct ww_mutex, base);
691 if (use_ww_ctx)
696 ww_mutex_set_context_slowpath(ww, ww_ctx);
692 ww_mutex_set_context_slowpath(ww, ww_ctx);
697 }
698
699 spin_unlock_mutex(&lock->wait_lock, flags);
700 preempt_enable();
701 return 0;
702
703err:
704 __set_task_state(task, TASK_RUNNING);
705 mutex_remove_waiter(lock, &waiter, task);

--- 329 unchanged lines hidden ---
693
694 spin_unlock_mutex(&lock->wait_lock, flags);
695 preempt_enable();
696 return 0;
697
698err:
699 __set_task_state(task, TASK_RUNNING);
700 mutex_remove_waiter(lock, &waiter, task);

--- 329 unchanged lines hidden ---