lock.h 1.2 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.
  10. * It can be used to implement bit locks.
  11. */
  12. #define test_and_set_bit_lock(nr, addr) test_and_set_bit(nr, addr)
  13. /**
  14. * clear_bit_unlock - Clear a bit in memory, for unlock
  15. * @nr: the bit to set
  16. * @addr: the address to start counting from
  17. *
  18. * This operation is atomic and provides release barrier semantics.
  19. */
  20. #define clear_bit_unlock(nr, addr) \
  21. do { \
  22. smp_mb__before_atomic(); \
  23. clear_bit(nr, addr); \
  24. } while (0)
  25. /**
  26. * __clear_bit_unlock - Clear a bit in memory, for unlock
  27. * @nr: the bit to set
  28. * @addr: the address to start counting from
  29. *
  30. * A weaker form of clear_bit_unlock() as used by __bit_lock_unlock(). If all
  31. * the bits in the word are protected by this lock some archs can use weaker
  32. * ops to safely unlock.
  33. *
  34. * See for example x86's implementation.
  35. */
  36. #define __clear_bit_unlock(nr, addr) \
  37. do { \
  38. smp_mb__before_atomic(); \
  39. clear_bit(nr, addr); \
  40. } while (0)
  41. #endif /* _ASM_GENERIC_BITOPS_LOCK_H_ */