From patchwork Tue Nov 25 22:37:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41512 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 703B425E72 for ; Tue, 25 Nov 2014 22:38:39 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf1052734lbv.1 for ; Tue, 25 Nov 2014 14:38:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=3gSx3HHRbbVtPEzw2CwPZn5ytC8DzKA7qUjWhEk+GK0=; b=HrVhkY64hoFP7rm3oQOoo7+h8A9eHXYuLz8tLdt4S4XuZXpT99QVnbjhX6f3X+aWK3 /xYmMX+i06dB/FrqRa1sDY82QZr8mvtPEkn6PsOlldy6IP+pui4CL0KiAogpvncUZu73 9qR06SZPFsuqmDn0WjkQGNblc4iFJMfmOV1XbMxPa8hp3NF/GlAmSf2IRNl92EoSG7rD daLp0xrpsEI6N5ZsDGpynN6dzxGxZAemJcdXki/pKONLp9PL6hR/GJT6oZeB5iPjjxqp ADVFvDs8dVTnnBvC1oNVFWw+RMuNtc19GbcBJkRFxJD/M6b9SdMCiThYCW3fRJSQoP2n 53Aw== X-Gm-Message-State: ALoCoQnHyiwkkVWaEmXxxaXaWBzDZqgvGtUJjizH/WMjwpuNOU9e6kIaMHpDHMJVIhG2SEq+U6w4 X-Received: by 10.180.19.42 with SMTP id b10mr7729914wie.0.1416955118001; Tue, 25 Nov 2014 14:38:38 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.9 with SMTP id w9ls670746law.1.gmail; Tue, 25 Nov 2014 14:38:37 -0800 (PST) X-Received: by 10.112.135.229 with SMTP id pv5mr30724935lbb.52.1416955117139; Tue, 25 Nov 2014 14:38:37 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id l8si2611390lag.90.2014.11.25.14.38.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Nov 2014 14:38:37 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id ge10so1471505lab.17 for ; Tue, 25 Nov 2014 14:38:37 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr30767923lbc.34.1416955117024; Tue, 25 Nov 2014 14:38:37 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp532041lbc; Tue, 25 Nov 2014 14:38:36 -0800 (PST) X-Received: by 10.52.74.106 with SMTP id s10mr13608237vdv.97.1416955116179; Tue, 25 Nov 2014 14:38:36 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id cj2si968735vdd.4.2014.11.25.14.38.35 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 25 Nov 2014 14:38:36 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XtOkj-00043P-LE; Tue, 25 Nov 2014 22:38:33 +0000 Received: from mail-lb0-f170.google.com ([209.85.217.170]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XtOkJ-00041Q-Se for lng-odp@lists.linaro.org; Tue, 25 Nov 2014 22:38:08 +0000 Received: by mail-lb0-f170.google.com with SMTP id w7so1487354lbi.1 for ; Tue, 25 Nov 2014 14:38:02 -0800 (PST) X-Received: by 10.152.205.11 with SMTP id lc11mr30894602lac.34.1416955082209; Tue, 25 Nov 2014 14:38:02 -0800 (PST) Received: from macmini.lan (84-217-193-77.tn.glocalnet.net. [84.217.193.77]) by mx.google.com with ESMTPSA id vr7sm696196lbb.21.2014.11.25.14.38.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Nov 2014 14:38:01 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 25 Nov 2014 23:37:48 +0100 Message-Id: <1416955068-6580-5-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416955068-6580-1-git-send-email-ola.liljedahl@linaro.org> References: <1416955068-6580-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 4/4] linux-generic: odp_spinlock[ch]: use odp_atomic_internal.h X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ola.liljedahl@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Ola Liljedahl --- Use definitions from odp_atomic_internal.h. platform/linux-generic/include/api/odp_spinlock.h | 2 +- platform/linux-generic/odp_spinlock.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/platform/linux-generic/include/api/odp_spinlock.h b/platform/linux-generic/include/api/odp_spinlock.h index 462ff97..7c299c8 100644 --- a/platform/linux-generic/include/api/odp_spinlock.h +++ b/platform/linux-generic/include/api/odp_spinlock.h @@ -30,7 +30,7 @@ extern "C" { * ODP spinlock */ typedef struct odp_spinlock_t { - volatile int lock; /**< @private Lock */ + char lock; /**< @private Lock */ } odp_spinlock_t; diff --git a/platform/linux-generic/odp_spinlock.c b/platform/linux-generic/odp_spinlock.c index 4eba015..5c7ef39 100644 --- a/platform/linux-generic/odp_spinlock.c +++ b/platform/linux-generic/odp_spinlock.c @@ -5,36 +5,41 @@ */ #include +#include #include void odp_spinlock_init(odp_spinlock_t *spinlock) { - __sync_lock_release(&spinlock->lock); + odp_atomic_flag_init(&spinlock->lock, 0); } void odp_spinlock_lock(odp_spinlock_t *spinlock) { - while (__sync_lock_test_and_set(&spinlock->lock, 1)) - while (spinlock->lock) + /* While the lock is already taken... */ + while (odp_atomic_flag_tas(&spinlock->lock)) + /* ...spin reading the flag (relaxed MM), + * the loop will exit when the lock becomes available + * and we will retry the TAS operation above */ + while (odp_atomic_flag_load(&spinlock->lock)) odp_spin(); } int odp_spinlock_trylock(odp_spinlock_t *spinlock) { - return (__sync_lock_test_and_set(&spinlock->lock, 1) == 0); + return (odp_atomic_flag_tas(&spinlock->lock) == 0); } void odp_spinlock_unlock(odp_spinlock_t *spinlock) { - __sync_lock_release(&spinlock->lock); + odp_atomic_flag_clear(&spinlock->lock); } int odp_spinlock_is_locked(odp_spinlock_t *spinlock) { - return spinlock->lock != 0; + return odp_atomic_flag_load(&spinlock->lock) != 0; }