From: Vineet Gupta Date: Sat, 8 Oct 2016 00:02:07 +0000 (-0700) Subject: ia64: implement atomic64_dec_if_positive X-Git-Tag: v4.9-rc1~73^2~22 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Flinux.git;a=commitdiff_plain;h=445ed0a0eac50d2a76441278a084554a4b9dcfda ia64: implement atomic64_dec_if_positive This is based on s390 version and needed to get rid of CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE Link: http://lkml.kernel.org/r/1473703083-8625-2-git-send-email-vgupta@synopsys.com Signed-off-by: Vineet Gupta Reported-by: kbuild test robot Cc: Tony Luck Cc: Fenghua Yu Cc: Ingo Molnar Cc: Peter Zijlstra Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h index f565ad376142..65d4bb2b6685 100644 --- a/arch/ia64/include/asm/atomic.h +++ b/arch/ia64/include/asm/atomic.h @@ -269,6 +269,22 @@ static __inline__ long atomic64_add_unless(atomic64_t *v, long a, long u) #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) +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; +} + /* * Atomically add I to V and return TRUE if the resulting value is * negative.