blob: c531d5afecc476cef51b8a3eff2f36c461d0907c [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}_dec_unless_positive(${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