From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754997AbcILR61 (ORCPT ); Mon, 12 Sep 2016 13:58:27 -0400 Received: from us01smtprelay-2.synopsys.com ([198.182.60.111]:47502 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753762AbcILR6X (ORCPT ); Mon, 12 Sep 2016 13:58:23 -0400 From: Vineet Gupta To: Tony Luck , Fenghua Yu , "Ingo Molnar" , Peter Zijlstra CC: , , Vineet Gupta , Subject: [PATCH v3 1/2] ia64: implement atomic64_dec_if_positive Date: Mon, 12 Sep 2016 10:58:02 -0700 Message-ID: <1473703083-8625-2-git-send-email-vgupta@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473703083-8625-1-git-send-email-vgupta@synopsys.com> References: <201609111259.q67d9T4B%fengguang.wu@intel.com> <1473703083-8625-1-git-send-email-vgupta@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.9.130.78] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is based on s390 version and needed to get rid of CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE Cc: Tony Luck Cc: Fenghua Yu Cc: Ingo Molnar Cc: Peter Zijlstra Cc: linux-ia64@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reported-by: kbuild test robot Signed-off-by: Vineet Gupta --- arch/ia64/include/asm/atomic.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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. -- 2.7.4