mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 19:00:25 +00:00
![Will Deacon](/assets/img/avatar_default.png)
A test_and_{}_bit() operation fails if the value of the bit is such that the modification does not take place. For example, if test_and_set_bit() returns 1. In these cases, follow the behaviour of cmpxchg and allow the operation to be unordered. This also applies to test_and_set_bit_lock() if the lock is found to be be taken already. Signed-off-by: Will Deacon <will.deacon@arm.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1518528619-20049-1-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
47 lines
1.3 KiB
C
47 lines
1.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_GENERIC_BITOPS_LOCK_H_
|
|
#define _ASM_GENERIC_BITOPS_LOCK_H_
|
|
|
|
/**
|
|
* test_and_set_bit_lock - Set a bit and return its old value, for lock
|
|
* @nr: Bit to set
|
|
* @addr: Address to count from
|
|
*
|
|
* This operation is atomic and provides acquire barrier semantics if
|
|
* the returned value is 0.
|
|
* It can be used to implement bit locks.
|
|
*/
|
|
#define test_and_set_bit_lock(nr, addr) test_and_set_bit(nr, addr)
|
|
|
|
/**
|
|
* clear_bit_unlock - Clear a bit in memory, for unlock
|
|
* @nr: the bit to set
|
|
* @addr: the address to start counting from
|
|
*
|
|
* This operation is atomic and provides release barrier semantics.
|
|
*/
|
|
#define clear_bit_unlock(nr, addr) \
|
|
do { \
|
|
smp_mb__before_atomic(); \
|
|
clear_bit(nr, addr); \
|
|
} while (0)
|
|
|
|
/**
|
|
* __clear_bit_unlock - Clear a bit in memory, for unlock
|
|
* @nr: the bit to set
|
|
* @addr: the address to start counting from
|
|
*
|
|
* A weaker form of clear_bit_unlock() as used by __bit_lock_unlock(). If all
|
|
* the bits in the word are protected by this lock some archs can use weaker
|
|
* ops to safely unlock.
|
|
*
|
|
* See for example x86's implementation.
|
|
*/
|
|
#define __clear_bit_unlock(nr, addr) \
|
|
do { \
|
|
smp_mb__before_atomic(); \
|
|
clear_bit(nr, addr); \
|
|
} while (0)
|
|
|
|
#endif /* _ASM_GENERIC_BITOPS_LOCK_H_ */
|
|
|