From patchwork Thu Nov 27 15:12:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41627 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D80E52486D for ; Thu, 27 Nov 2014 15:13:42 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id u10sf3140098lbd.10 for ; Thu, 27 Nov 2014 07:13:41 -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=hNvXxIjO8pdBGapN0dwW50WBbUnLu3++Rreia22OQP0=; b=kxaMrErunfi+bDCbEmkXN03uj7cCQPlvYOqiCH2xzpiTVJSY20Ql8UGVqqHCK8qZ32 cgnNlSM1Yuuu1NCrrWIy0Db0zhpr7ezPADa5am7u1p8aHzuA7hC2MnMyBUSUyObp5SJE iBWhRtptQYIZ3xQyjmqln0F/ieFUVfTj0yVRbraXUSWTQkPiaG00Ax4ie1RAJmeD+oMS DmzAjJWGLdlSEPnp3nLpIvlTBV/XkhcXFk/5Dk3fJuHv47nl5jboCfEY3MjOyl1bT7A9 DlQ90YFPlCrr14jnQACbVHebAhvngR8rMkYodHB59k7aUtBZT7S7d9OEIxKUQnDDUkrt qCgQ== X-Gm-Message-State: ALoCoQk5aAOvUM6mX05YM87zyaWvf4XAgGaZV+gTGc9QJtOQf+mBTkdzYPcMYQT8llpQorhmdjyS X-Received: by 10.180.24.35 with SMTP id r3mr6252074wif.0.1417101221802; Thu, 27 Nov 2014 07:13:41 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.166 with SMTP id t6ls925491lat.20.gmail; Thu, 27 Nov 2014 07:13:41 -0800 (PST) X-Received: by 10.152.37.100 with SMTP id x4mr39726246laj.22.1417101221550; Thu, 27 Nov 2014 07:13:41 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id f8si7532149lab.102.2014.11.27.07.13.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Nov 2014 07:13:41 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id gd6so4427742lab.33 for ; Thu, 27 Nov 2014 07:13:41 -0800 (PST) X-Received: by 10.112.138.137 with SMTP id qq9mr39410439lbb.80.1417101221478; Thu, 27 Nov 2014 07:13:41 -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 ew9csp811783lbc; Thu, 27 Nov 2014 07:13:40 -0800 (PST) X-Received: by 10.170.121.142 with SMTP id n136mr42922554ykb.123.1417101220066; Thu, 27 Nov 2014 07:13:40 -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 a2si8777821qae.86.2014.11.27.07.13.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 27 Nov 2014 07:13:40 -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 1Xu0lF-0004i8-3N; Thu, 27 Nov 2014 15:13:37 +0000 Received: from mail-lb0-f173.google.com ([209.85.217.173]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xu0ku-0004gi-CD for lng-odp@lists.linaro.org; Thu, 27 Nov 2014 15:13:16 +0000 Received: by mail-lb0-f173.google.com with SMTP id z12so4238875lbi.4 for ; Thu, 27 Nov 2014 07:13:10 -0800 (PST) X-Received: by 10.152.37.201 with SMTP id a9mr37996095lak.53.1417101190564; Thu, 27 Nov 2014 07:13:10 -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.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Nov 2014 07:13:09 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 27 Nov 2014 16:12:59 +0100 Message-Id: <1417101181-13500-4-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 3/5] linux-generic: odp_rwlock[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.46 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_rwlock.h | 4 ++- platform/linux-generic/odp_rwlock.c | 35 ++++++++++++------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/platform/linux-generic/include/api/odp_rwlock.h b/platform/linux-generic/include/api/odp_rwlock.h index a880f92..59cf9cc 100644 --- a/platform/linux-generic/include/api/odp_rwlock.h +++ b/platform/linux-generic/include/api/odp_rwlock.h @@ -13,6 +13,8 @@ * ODP RW Locks */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -28,7 +30,7 @@ extern "C" { * read lock count > 0 */ typedef struct { - volatile int32_t cnt; /**< -1 Write lock, + odp_atomic_u32_t cnt; /**< -1 Write lock, > 0 for Read lock. */ } odp_rwlock_t; diff --git a/platform/linux-generic/odp_rwlock.c b/platform/linux-generic/odp_rwlock.c index 2f6a255..01a3b4e 100644 --- a/platform/linux-generic/odp_rwlock.c +++ b/platform/linux-generic/odp_rwlock.c @@ -6,64 +6,63 @@ #include #include +#include #include #include void odp_rwlock_init(odp_rwlock_t *rwlock) { - rwlock->cnt = 0; + odp_atomic_init_u32(&rwlock->cnt, 0); } void odp_rwlock_read_lock(odp_rwlock_t *rwlock) { - int32_t cnt; + uint32_t cnt; int is_locked = 0; while (is_locked == 0) { - cnt = rwlock->cnt; + cnt = _odp_atomic_u32_load_mm(&rwlock->cnt, _ODP_MEMMODEL_RLX); /* waiting for read lock */ - if (cnt < 0) { + if ((int32_t)cnt < 0) { odp_spin(); continue; } - is_locked = __atomic_compare_exchange_n(&rwlock->cnt, + is_locked = _odp_atomic_u32_cmp_xchg_strong_mm(&rwlock->cnt, &cnt, cnt + 1, - false/*strong*/, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); + _ODP_MEMMODEL_ACQ, + _ODP_MEMMODEL_RLX); } } void odp_rwlock_read_unlock(odp_rwlock_t *rwlock) { - (void)__atomic_sub_fetch(&rwlock->cnt, 1, __ATOMIC_RELEASE); + _odp_atomic_u32_sub_mm(&rwlock->cnt, 1, _ODP_MEMMODEL_RLS); } void odp_rwlock_write_lock(odp_rwlock_t *rwlock) { - int32_t cnt; + uint32_t cnt; int is_locked = 0; while (is_locked == 0) { - int32_t zero = 0; - cnt = rwlock->cnt; + uint32_t zero = 0; + cnt = _odp_atomic_u32_load_mm(&rwlock->cnt, _ODP_MEMMODEL_RLX); /* lock aquired, wait */ if (cnt != 0) { odp_spin(); continue; } - is_locked = __atomic_compare_exchange_n(&rwlock->cnt, + is_locked = _odp_atomic_u32_cmp_xchg_strong_mm(&rwlock->cnt, &zero, - -1, - false/*strong*/, - __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); + (uint32_t)-1, + _ODP_MEMMODEL_ACQ, + _ODP_MEMMODEL_RLX); } } void odp_rwlock_write_unlock(odp_rwlock_t *rwlock) { - (void)__atomic_add_fetch(&rwlock->cnt, 1, __ATOMIC_RELEASE); + _odp_atomic_u32_store_mm(&rwlock->cnt, 0, _ODP_MEMMODEL_RLS); }