On Tue, Aug 23, 2016 at 02:46:18PM +0200, Peter Zijlstra wrote:
> There's a number of iffy in mutex because mutex::count and
> mutex::owner are two different fields; this too is the reason
> MUTEX_SPIN_ON_OWNER and DEBUG_MUTEX are mutually exclusive.
> 
> Cure this by folding them into a single atomic_long_t field.
> 
> This nessecairly kills all the architecture specific mutex code.
> 
> Signed-off-by: Peter Zijlstra (Intel) <pet...@infradead.org>

[...]

>  void __sched mutex_unlock(struct mutex *lock)
>  {
> -     /*
> -      * The unlocking fastpath is the 0->1 transition from 'locked'
> -      * into 'unlocked' state:
> -      */
> -#ifndef CONFIG_DEBUG_MUTEXES
> -     /*
> -      * When debugging is enabled we must not clear the owner before time,
> -      * the slow path will always be taken, and that clears the owner field
> -      * after verifying that it was indeed current.
> -      */
> -     mutex_clear_owner(lock);
> +     unsigned long owner;
> +
> +#ifdef CONFIG_DEBUG_MUTEXES
> +     DEBUG_LOCKS_WARN_ON(__mutex_owner(lock) != current);
>  #endif
> -     __mutex_fastpath_unlock(&lock->count, __mutex_unlock_slowpath);
> -}
>  
> +     owner = atomic_long_read(&lock->owner);
> +     for (;;) {
> +             unsigned long old;
> +
> +             old = atomic_long_cmpxchg_release(&lock->owner, owner, owner & 
> 0x03);
> +             if (old == owner)
> +                     break;
> +
> +             owner = old;
> +     }

Can you rewrite this using atomic_long_fetch_and_release?

Will

Reply via email to