blob: 95d8ce48233ff4569bd67dab82c655c8ae1c6db2 [file] [log] [blame]
Mark Rutlandace9bad2018-09-04 11:48:25 +01001cat <<EOF
Marco Elver765dcd22019-11-26 15:04:05 +01002static __always_inline bool
Mark Rutlandf3e615b2021-07-13 11:52:50 +01003arch_${atomic}_inc_unless_negative(${atomic}_t *v)
Mark Rutlandace9bad2018-09-04 11:48:25 +01004{
Mark Rutlandf3e615b2021-07-13 11:52:50 +01005 ${int} c = arch_${atomic}_read(v);
Mark Rutlandace9bad2018-09-04 11:48:25 +01006
7 do {
8 if (unlikely(c < 0))
9 return false;
Mark Rutlandf3e615b2021-07-13 11:52:50 +010010 } while (!arch_${atomic}_try_cmpxchg(v, &c, c + 1));
Mark Rutlandace9bad2018-09-04 11:48:25 +010011
12 return true;
13}
14EOF