lock.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_GENERIC_BITOPS_LOCK_H_
  3. #define _ASM_GENERIC_BITOPS_LOCK_H_
  4. /**
  5. * test_and_set_bit_lock - Set a bit and return its old value, for lock
  6. * @nr: Bit to set
  7. * @addr: Address to count from
  8. *
  9. * This operation is atomic and provides acquire barrier semantics if
  10. * the returned value is 0.
  11. * It can be used to implement bit locks.
  12. */
  13. #define test_and_set_bit_lock(nr, addr) test_and_set_bit(nr, addr)
  14. /**
  15. * clear_bit_unlock - Clear a bit in memory, for unlock
  16. * @nr: the bit to set
  17. * @addr: the address to start counting from
  18. *
  19. * This operation is atomic and provides release barrier semantics.
  20. */
  21. #define clear_bit_unlock(nr, addr) \
  22. do { \
  23. smp_mb__before_atomic(); \
  24. clear_bit(nr, addr); \
  25. } while (0)
  26. /**
  27. * __clear_bit_unlock - Clear a bit in memory, for unlock
  28. * @nr: the bit to set
  29. * @addr: the address to start counting from
  30. *
  31. * A weaker form of clear_bit_unlock() as used by __bit_lock_unlock(). If all
  32. * the bits in the word are protected by this lock some archs can use weaker
  33. * ops to safely unlock.
  34. *
  35. * See for example x86's implementation.
  36. */
  37. #define __clear_bit_unlock(nr, addr) \
  38. do { \
  39. smp_mb__before_atomic(); \
  40. clear_bit(nr, addr); \
  41. } while (0)
  42. #endif /* _ASM_GENERIC_BITOPS_LOCK_H_ */