inc_unless_negative 249 B

1234567891011121314
  1. cat <<EOF
  2. static __always_inline bool
  3. arch_${atomic}_inc_unless_negative(${atomic}_t *v)
  4. {
  5. ${int} c = arch_${atomic}_read(v);
  6. do {
  7. if (unlikely(c < 0))
  8. return false;
  9. } while (!arch_${atomic}_try_cmpxchg(v, &c, c + 1));
  10. return true;
  11. }
  12. EOF