fetch_add_unless 552 B

1234567891011121314151617181920212223
  1. cat << EOF
  2. /**
  3. * arch_${atomic}_fetch_add_unless - add unless the number is already a given value
  4. * @v: pointer of type ${atomic}_t
  5. * @a: the amount to add to v...
  6. * @u: ...unless v is equal to u.
  7. *
  8. * Atomically adds @a to @v, so long as @v was not already @u.
  9. * Returns original value of @v
  10. */
  11. static __always_inline ${int}
  12. arch_${atomic}_fetch_add_unless(${atomic}_t *v, ${int} a, ${int} u)
  13. {
  14. ${int} c = arch_${atomic}_read(v);
  15. do {
  16. if (unlikely(c == u))
  17. break;
  18. } while (!arch_${atomic}_try_cmpxchg(v, &c, c + a));
  19. return c;
  20. }
  21. EOF