atomic.h 914 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef _LINUX_ATOMIC_H
  2. #define _LINUX_ATOMIC_H
  3. #include <asm/atomic.h>
  4. /**
  5. * atomic_inc_not_zero_hint - increment if not null
  6. * @v: pointer of type atomic_t
  7. * @hint: probable value of the atomic before the increment
  8. *
  9. * This version of atomic_inc_not_zero() gives a hint of probable
  10. * value of the atomic. This helps processor to not read the memory
  11. * before doing the atomic read/modify/write cycle, lowering
  12. * number of bus transactions on some arches.
  13. *
  14. * Returns: 0 if increment was not done, 1 otherwise.
  15. */
  16. #ifndef atomic_inc_not_zero_hint
  17. static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
  18. {
  19. int val, c = hint;
  20. /* sanity test, should be removed by compiler if hint is a constant */
  21. if (!hint)
  22. return atomic_inc_not_zero(v);
  23. do {
  24. val = atomic_cmpxchg(v, c, c + 1);
  25. if (val == c)
  26. return 1;
  27. c = val;
  28. } while (c);
  29. return 0;
  30. }
  31. #endif
  32. #endif /* _LINUX_ATOMIC_H */