blob: 527adec89c3783dc55416720dd8665dd1531ae3b [file] [log] [blame]
Mark Rutlandace9bad2018-09-04 11:48:25 +01001cat <<EOF
Marco Elver765dcd22019-11-26 15:04:05 +01002static __always_inline ${ret}
Peter Zijlstra37f81732020-01-24 22:13:03 +01003${arch}${atomic}_dec_if_positive(${atomic}_t *v)
Mark Rutlandace9bad2018-09-04 11:48:25 +01004{
Peter Zijlstra37f81732020-01-24 22:13:03 +01005 ${int} dec, c = ${arch}${atomic}_read(v);
Mark Rutlandace9bad2018-09-04 11:48:25 +01006
7 do {
8 dec = c - 1;
9 if (unlikely(dec < 0))
10 break;
Peter Zijlstra37f81732020-01-24 22:13:03 +010011 } while (!${arch}${atomic}_try_cmpxchg(v, &c, dec));
Mark Rutlandace9bad2018-09-04 11:48:25 +010012
13 return dec;
14}
15EOF