| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | cat <<EOF |
| 2 | static inline bool | ||||
| 3 | ${atomic}_inc_unless_negative(${atomic}_t *v) | ||||
| 4 | { | ||||
| 5 | ${int} c = ${atomic}_read(v); | ||||
| 6 | |||||
| 7 | do { | ||||
| 8 | if (unlikely(c < 0)) | ||||
| 9 | return false; | ||||
| 10 | } while (!${atomic}_try_cmpxchg(v, &c, c + 1)); | ||||
| 11 | |||||
| 12 | return true; | ||||
| 13 | } | ||||
| 14 | EOF | ||||