From patchwork Thu Nov 27 15:13:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41628 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 391B52486D for ; Thu, 27 Nov 2014 15:13:47 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf3301511eek.5 for ; Thu, 27 Nov 2014 07:13:46 -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=csbLjnTPpQUceO3VNKjzijiTXEzlaPODE/1e5oqCBLM=; b=EpY/3R15wpHNVzeWsQ7eI1aKndO7U01HS0Rr+LmTe7PEazB+tLVgs2a7f5xHPrnnRP LOjoX5nknx0CNrGVVbvr0kU+iqB06bL1hytJl84nRiS0kBD/h9fXeJbTOsBevd1LZCyu jw077LIi46alCo/r0Je40x3E5Gqhj0xa9C6DM0amJc7z+rrulTG3zYUa9KvaEEBnCM/C uTKUM6vohWO0n50d1Ck9Si+cxevbi2t/5sEjh1eTQNYz61MWw5P5CEv5OvGo8V15tpnw TMaoVnNOHJXPUQwdlfVWf/mVSdqMafVDnNAq5XMze5fulZPCquvjtDbqiYiz8TruhbVW VNag== X-Gm-Message-State: ALoCoQl9AnteVv/SbqD7owLczToAd88S9nHFFXwHLELSEjWrUoDYECVQ3U4RNMJvcifVBY67ITXF X-Received: by 10.112.169.101 with SMTP id ad5mr3136165lbc.1.1417101226424; Thu, 27 Nov 2014 07:13:46 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.11.6 with SMTP id ee6ls540132lad.7.gmail; Thu, 27 Nov 2014 07:13:45 -0800 (PST) X-Received: by 10.112.93.231 with SMTP id cx7mr37849106lbb.89.1417101225586; Thu, 27 Nov 2014 07:13:45 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id 6si7567377laj.58.2014.11.27.07.13.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Nov 2014 07:13:45 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id gm9so4292711lab.26 for ; Thu, 27 Nov 2014 07:13:45 -0800 (PST) X-Received: by 10.152.9.7 with SMTP id v7mr39702973laa.40.1417101225463; Thu, 27 Nov 2014 07:13:45 -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 ew9csp811788lbc; Thu, 27 Nov 2014 07:13:44 -0800 (PST) X-Received: by 10.229.64.134 with SMTP id e6mr54264962qci.11.1417101224038; Thu, 27 Nov 2014 07:13:44 -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 x4si8784914qai.81.2014.11.27.07.13.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 27 Nov 2014 07:13:44 -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 1Xu0lK-0004kZ-Am; Thu, 27 Nov 2014 15:13:42 +0000 Received: from mail-la0-f52.google.com ([209.85.215.52]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xu0kv-0004gj-9S for lng-odp@lists.linaro.org; Thu, 27 Nov 2014 15:13:17 +0000 Received: by mail-la0-f52.google.com with SMTP id q1so4280487lam.39 for ; Thu, 27 Nov 2014 07:13:11 -0800 (PST) X-Received: by 10.152.5.6 with SMTP id o6mr40083033lao.8.1417101191780; Thu, 27 Nov 2014 07:13:11 -0800 (PST) Received: from macmini.lan (84-217-193-77.tn.glocalnet.net. [84.217.193.77]) by mx.google.com with ESMTPSA id y3sm434075lad.7.2014.11.27.07.13.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Nov 2014 07:13:11 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 27 Nov 2014 16:13:00 +0100 Message-Id: <1417101181-13500-5-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417101181-13500-1-git-send-email-ola.liljedahl@linaro.org> References: <1417101181-13500-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 4/5] 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.53 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 Reviewed-by: Bill Fischofer --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) 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..4dfd3cf 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; }