RE: [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Vineet Gupta <Vineet.Gupta1@xxxxxxxxxxxx>, "Yu, Fenghua" <fenghua.yu@xxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>
- Subject: RE: [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive
- From: "Luck, Tony" <tony.luck@xxxxxxxxx>
- Date: Mon, 12 Sep 2016 18:26:07 +0000
- Accept-language: en-US
- Cc: "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>, "linux-snps-arc@xxxxxxxxxxxxxxxxxxx" <linux-snps-arc@xxxxxxxxxxxxxxxxxxx>, "linux-ia64@xxxxxxxxxxxxxxx" <linux-ia64@xxxxxxxxxxxxxxx>
- In-reply-to: <1473702432-8116-2-git-send-email-vgupta@synopsys.com>
- References: <1473702432-8116-1-git-send-email-vgupta@synopsys.com> <1473702432-8116-2-git-send-email-vgupta@synopsys.com>
+static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
+{
+ long c, old, dec;
+ c = atomic64_read(v);
+ for (;;) {
+ dec = c - 1;
+ if (unlikely(dec < 0))
+ break;
+ old = atomic64_cmpxchg((v), c, dec);
+ if (likely(old == c))
+ break;
+ c = old;
+ }
+ return dec;
+}
I was about to say "add a cpu_relax()" in the bottom of that loop. But none of the other
atomic ops that spin on a cmpxchg do that ... so:
Acked-by: Tony Luck <tony.luck@xxxxxxxxx>
-Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]