atomic.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #ifndef CONFIG_ARCH_HAS_ATOMIC_OR
  33. static inline void atomic_or(int i, atomic_t *v)
  34. {
  35. int old;
  36. int new;
  37. do {
  38. old = atomic_read(v);
  39. new = old | i;
  40. } while (atomic_cmpxchg(v, old, new) != old);
  41. }
  42. #endif /* #ifndef CONFIG_ARCH_HAS_ATOMIC_OR */
  43. #endif /* _LINUX_ATOMIC_H */