summaryrefslogtreecommitdiffstats
path: root/scripts/atomic/fallbacks/dec_if_positive
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/atomic/fallbacks/dec_if_positive')
-rw-r--r--scripts/atomic/fallbacks/dec_if_positive15
1 files changed, 15 insertions, 0 deletions
diff --git a/scripts/atomic/fallbacks/dec_if_positive b/scripts/atomic/fallbacks/dec_if_positive
new file mode 100644
index 000000000000..c52eacec43c8
--- /dev/null
+++ b/scripts/atomic/fallbacks/dec_if_positive
@@ -0,0 +1,15 @@
+cat <<EOF
+static inline ${ret}
+${atomic}_dec_if_positive(${atomic}_t *v)
+{
+ ${int} dec, c = ${atomic}_read(v);
+
+ do {
+ dec = c - 1;
+ if (unlikely(dec < 0))
+ break;
+ } while (!${atomic}_try_cmpxchg(v, &c, dec));
+
+ return dec;
+}
+EOF