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 bool |
Mark Rutland | f3e615b | 2021-07-13 11:52:50 +0100 | [diff] [blame] | 3 | arch_${atomic}_dec_unless_positive(${atomic}_t *v) |
Mark Rutland | ace9bad | 2018-09-04 11:48:25 +0100 | [diff] [blame] | 4 | { |
Mark Rutland | f3e615b | 2021-07-13 11:52:50 +0100 | [diff] [blame] | 5 | ${int} c = arch_${atomic}_read(v); |
Mark Rutland | ace9bad | 2018-09-04 11:48:25 +0100 | [diff] [blame] | 6 | |
7 | do { | ||||
8 | if (unlikely(c > 0)) | ||||
9 | return false; | ||||
Mark Rutland | f3e615b | 2021-07-13 11:52:50 +0100 | [diff] [blame] | 10 | } while (!arch_${atomic}_try_cmpxchg(v, &c, c - 1)); |
Mark Rutland | ace9bad | 2018-09-04 11:48:25 +0100 | [diff] [blame] | 11 | |
12 | return true; | ||||
13 | } | ||||
14 | EOF |