Skip to content
Snippets Groups Projects
Select Git revision
  • fff168b028c767ac0497ae2450bb4043fc546b38
  • master default protected
  • android-msm-bullhead-3.10-nougat_kgdb_less_changes
  • android-msm-bullhead-3.10-nougat_kgdb
  • android-msm-bullhead-3.10-nougat_klist
  • android-4.4
  • android-msm-vega-4.4-oreo-daydream
  • android-msm-wahoo-4.4-p-preview-5
  • android-msm-wahoo-4.4-pie
  • android-msm-marlin-3.18-p-preview-5
  • android-msm-marlin-3.18-pie
  • android-msm-wahoo-2018.07-oreo-m2
  • android-msm-wahoo-2018.07-oreo-m4
  • android-msm-wahoo-4.4-p-preview-4
  • android-msm-bullhead-3.10-oreo-m6
  • android-msm-angler-3.10-oreo-m6
  • android-msm-marlin-3.18-p-preview-4
  • android-msm-stargazer-3.18-oreo-wear-dr
  • android-msm-catshark-3.18-oreo-wear-dr
  • android-msm-wahoo-4.4-oreo-m2
  • android-msm-wahoo-4.4-oreo-m4
  • android-daydreamos-8.0.0_r0.5
  • android-8.1.0_r0.92
  • android-8.1.0_r0.91
  • android-daydreamos-8.0.0_r0.4
  • android-p-preview-5_r0.2
  • android-p-preview-5_r0.1
  • android-9.0.0_r0.5
  • android-9.0.0_r0.4
  • android-9.0.0_r0.2
  • android-9.0.0_r0.1
  • android-8.1.0_r0.81
  • android-8.1.0_r0.80
  • android-8.1.0_r0.78
  • android-8.1.0_r0.76
  • android-8.1.0_r0.75
  • android-8.1.0_r0.72
  • android-8.1.0_r0.70
  • android-p-preview-4_r0.2
  • android-p-preview-4_r0.1
  • android-wear-8.0.0_r0.30
41 results

rtmutex.c

Blame
  • rtmutex.c 26.30 KiB
    /*
     * RT-Mutexes: simple blocking mutual exclusion locks with PI support
     *
     * started by Ingo Molnar and Thomas Gleixner.
     *
     *  Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
     *  Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
     *  Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
     *  Copyright (C) 2006 Esben Nielsen
     *
     *  See Documentation/rt-mutex-design.txt for details.
     */
    #include <linux/spinlock.h>
    #include <linux/export.h>
    #include <linux/sched.h>
    #include <linux/timer.h>
    
    #include "rtmutex_common.h"
    
    /*
     * lock->owner state tracking:
     *
     * lock->owner holds the task_struct pointer of the owner. Bit 0
     * is used to keep track of the "lock has waiters" state.
     *
     * owner	bit0
     * NULL		0	lock is free (fast acquire possible)
     * NULL		1	lock is free and has waiters and the top waiter
     *				is going to take the lock*
     * taskpointer	0	lock is held (fast release possible)
     * taskpointer	1	lock is held and has waiters**
     *
     * The fast atomic compare exchange based acquire and release is only
     * possible when bit 0 of lock->owner is 0.
     *
     * (*) It also can be a transitional state when grabbing the lock
     * with ->wait_lock is held. To prevent any fast path cmpxchg to the lock,
     * we need to set the bit0 before looking at the lock, and the owner may be
     * NULL in this small time, hence this can be a transitional state.
     *
     * (**) There is a small time when bit 0 is set but there are no
     * waiters. This can happen when grabbing the lock in the slow path.
     * To prevent a cmpxchg of the owner releasing the lock, we need to
     * set this bit before looking at the lock.
     */
    
    static void
    rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner)
    {
    	unsigned long val = (unsigned long)owner;
    
    	if (rt_mutex_has_waiters(lock))
    		val |= RT_MUTEX_HAS_WAITERS;
    
    	lock->owner = (struct task_struct *)val;
    }
    
    static inline void clear_rt_mutex_waiters(struct rt_mutex *lock)
    {
    	lock->owner = (struct task_struct *)
    			((unsigned long)lock->owner & ~RT_MUTEX_HAS_WAITERS);
    }
    
    static void fixup_rt_mutex_waiters(struct rt_mutex *lock)
    {
    	if (!rt_mutex_has_waiters(lock))
    		clear_rt_mutex_waiters(lock);
    }
    
    /*