• M
    wait_event_interruptible_locked() interface · 22c43c81
    Michal Nazarewicz 提交于
    New wait_event_interruptible{,_exclusive}_locked{,_irq} macros added.
    They work just like versions without _locked* suffix but require the
    wait queue's lock to be held.  Also __wake_up_locked() is now exported
    as to pair it with the above macros.
    
    The use case of this new facility is when one uses wait queue's lock
    to  protect a data structure.  This may be advantageous if the
    structure needs to be protected by a spinlock anyway.  In particular,
    with additional spinlock the following code has to be used to wait
    for a condition:
    
    spin_lock(&data.lock);
    ...
    for (ret = 0; !ret && !(condition); ) {
    	spin_unlock(&data.lock);
    	ret = wait_event_interruptible(data.wqh, (condition));
    	spin_lock(&data.lock);
    }
    ...
    spin_unlock(&data.lock);
    
    This looks bizarre plus wait_event_interruptible() locks the wait
    queue's lock anyway so there is a unlock+lock sequence where it could
    be avoided.
    
    To avoid those problems and benefit from wait queue's lock, a code
    similar to the following should be used:
    
    /* Waiting */
    spin_lock(&data.wqh.lock);
    ...
    ret = wait_event_interruptible_locked(data.wqh, (condition));
    ...
    spin_unlock(&data.wqh.lock);
    
    /* Waiting exclusively */
    spin_lock(&data.whq.lock);
    ...
    ret = wait_event_interruptible_exclusive_locked(data.whq, (condition));
    ...
    spin_unlock(&data.whq.lock);
    
    /* Waking up */
    spin_lock(&data.wqh.lock);
    ...
    wake_up_locked(&data.wqh);
    ...
    spin_unlock(&data.wqh.lock);
    
    When spin_lock_irq() is used matching versions of macros need to be
    used (*_locked_irq()).
    Signed-off-by: NMichal Nazarewicz <m.nazarewicz@samsung.com>
    Cc: Kyungmin Park <kyungmin.park@samsung.com>
    Cc: Marek Szyprowski <m.szyprowski@samsung.com>
    Cc: Ingo Molnar <mingo@elte.hu>
    Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
    Cc: Takashi Iwai <tiwai@suse.de>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Andreas Herrmann <andreas.herrmann3@amd.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Mike Galbraith <efault@gmx.de>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
    22c43c81
wait.h 21.4 KB