Mark Rutland | ace9bad | 2018-09-04 11:48:25 +0100 | [diff] [blame] | 1 | cat <<EOF |
Marco Elver | 765dcd2 | 2019-11-26 15:04:05 +0100 | [diff] [blame] | 2 | static __always_inline ${ret} |
Peter Zijlstra | 37f8173 | 2020-01-24 22:13:03 +0100 | [diff] [blame] | 3 | ${arch}${atomic}_dec_if_positive(${atomic}_t *v) |
Mark Rutland | ace9bad | 2018-09-04 11:48:25 +0100 | [diff] [blame] | 4 | { |
Peter Zijlstra | 37f8173 | 2020-01-24 22:13:03 +0100 | [diff] [blame] | 5 | ${int} dec, c = ${arch}${atomic}_read(v); |
Mark Rutland | ace9bad | 2018-09-04 11:48:25 +0100 | [diff] [blame] | 6 | |
7 | do { | ||||
8 | dec = c - 1; | ||||
9 | if (unlikely(dec < 0)) | ||||
10 | break; | ||||
Peter Zijlstra | 37f8173 | 2020-01-24 22:13:03 +0100 | [diff] [blame] | 11 | } while (!${arch}${atomic}_try_cmpxchg(v, &c, dec)); |
Mark Rutland | ace9bad | 2018-09-04 11:48:25 +0100 | [diff] [blame] | 12 | |
13 | return dec; | ||||
14 | } | ||||
15 | EOF |