summaryrefslogtreecommitdiffstats
path: root/scripts/atomic/fallbacks/dec_if_positive
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/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 100755
index 000000000..527adec89
--- /dev/null
+++ b/scripts/atomic/fallbacks/dec_if_positive
@@ -0,0 +1,15 @@
+cat <<EOF
+static __always_inline ${ret}
+${arch}${atomic}_dec_if_positive(${atomic}_t *v)
+{
+ ${int} dec, c = ${arch}${atomic}_read(v);
+
+ do {
+ dec = c - 1;
+ if (unlikely(dec < 0))
+ break;
+ } while (!${arch}${atomic}_try_cmpxchg(v, &c, dec));
+
+ return dec;
+}
+EOF