From patchwork Wed May 23 13:35:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 136663 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp910268lji; Wed, 23 May 2018 06:39:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrCEV3ZgthWBs728GpCN6qyAvTomwjypwxcTTLJEfKAji52F8S9SgfjkC2CzTZfW+7riwA/ X-Received: by 2002:a17:902:9a98:: with SMTP id w24-v6mr3113230plp.9.1527082744384; Wed, 23 May 2018 06:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527082744; cv=none; d=google.com; s=arc-20160816; b=KVeLREiBHYO7Fz7dTHkl6sFS7CwSXoTfEeDwdV4e2GDagDfA1JoEiTI1BycSkV639M oeZVuMnf8lhibcrrvU0+CKBAIzN7NoKL1HMMOzpCdDJKE+KYRlfH8M64CAmW1oGASeYD 7oyFfHxwnXRuk2vTvekGCJNUVeJ12KCvg7lCO9BTwQwecsmlyWdYeo+yQgQiJLo7O5/g ncaF0CEk30wCarXDd3XXUksEKo+AfjBBDAfTdBrHq9WF/TlWKjxvpr89YYaEcN5aBDVt mRlUB7mTaZf3mOnFGwZ0p16pJSe47kSOOiF7OezPQyiy4UYm1iCCgT2dyq1b36dITZuy JEKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=DWp7ST4+Tk0yvGvEFDN/p4r+tGbg9C7eUosmQ9FVHcI=; b=p3MhKhAaiK5+Z2S9RiUL3JtTkDgJWD8GTSYJrApRQXOdlW8J3RGNlxrGoMTXkJp/rG zn2GnpjaPq54nseJH1nNvyq80779HNWCH86ngnaYgXCX48zzDWVOTVP/EHinlAZbX76J N/m1jtKV/A+hmmh9z9PHPOD6kmbCRNeqa3gnM3RKRZmInwGkfz8gAdItL1/Lb/dXTJ/8 96l3pK4k6jY59Dogsdr2Cs4KuBP9uNr1v+m7aAIHxysSROwApw3FkCejkIQBcPViCy1Y /dEth6J2P+IxnrDQz1xoQU27ZVSiR4jECbVcyTPmE6ZK3PRrLCIy9qecSxK1qHeHNa95 1kCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g92-v6si18937717plg.342.2018.05.23.06.39.04; Wed, 23 May 2018 06:39:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933218AbeEWNjC (ORCPT + 30 others); Wed, 23 May 2018 09:39:02 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55376 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933130AbeEWNgS (ORCPT ); Wed, 23 May 2018 09:36:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 30A17165D; Wed, 23 May 2018 06:36:18 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 001C73F24A; Wed, 23 May 2018 06:36:16 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Boqun Feng , Peter Zijlstra , Will Deacon , Arnd Bergmann Subject: [PATCH 06/13] atomics/generic: define atomic64_fetch_add_unless() Date: Wed, 23 May 2018 14:35:26 +0100 Message-Id: <20180523133533.1076-7-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180523133533.1076-1-mark.rutland@arm.com> References: <20180523133533.1076-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As a step towards unifying the atomic/atomic64/atomic_long APIs, this patch converts the generic implementation of atomic64_add_unless() into a generic implementation of atomic64_fetch_add_unless(). A wrapper in will build atomic_add_unless() atop of this, provided it is given a preprocessor definition. No functional change is intended as a result of this patch. Signed-off-by: Mark Rutland Cc: Boqun Feng Cc: Peter Zijlstra Cc: Will Deacon Cc: Arnd Bergmann --- include/asm-generic/atomic64.h | 3 ++- lib/atomic64.c | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) -- 2.11.0 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h index e9a94b7a4d0a..b0aa425361ad 100644 --- a/include/asm-generic/atomic64.h +++ b/include/asm-generic/atomic64.h @@ -52,7 +52,8 @@ ATOMIC64_OPS(xor) extern long long atomic64_dec_if_positive(atomic64_t *v); extern long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n); extern long long atomic64_xchg(atomic64_t *v, long long new); -extern int atomic64_add_unless(atomic64_t *v, long long a, long long u); +extern long long atomic64_fetch_add_unless(atomic64_t *v, long long a, long long u); +#define atomic64_fetch_add_unless atomic64_fetch_add_unless #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0) #define atomic64_inc(v) atomic64_add(1LL, (v)) diff --git a/lib/atomic64.c b/lib/atomic64.c index 53c2d5edc826..fb2a38af5ae8 100644 --- a/lib/atomic64.c +++ b/lib/atomic64.c @@ -178,18 +178,17 @@ long long atomic64_xchg(atomic64_t *v, long long new) } EXPORT_SYMBOL(atomic64_xchg); -int atomic64_add_unless(atomic64_t *v, long long a, long long u) +long long atomic64_fetch_add_unless(atomic64_t *v, long long a, long long u) { unsigned long flags; raw_spinlock_t *lock = lock_addr(v); - int ret = 0; + long long val; raw_spin_lock_irqsave(lock, flags); - if (v->counter != u) { + val = v->counter; + if (val != u) v->counter += a; - ret = 1; - } raw_spin_unlock_irqrestore(lock, flags); - return ret; + return val; } -EXPORT_SYMBOL(atomic64_add_unless); +EXPORT_SYMBOL(atomic64_fetch_add_unless);