From patchwork Thu Nov 20 11:53:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41235 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7F62E23C27 for ; Thu, 20 Nov 2014 11:54:41 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id c13sf1968987eek.2 for ; Thu, 20 Nov 2014 03:54:40 -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=dSBymKvC0fogQwUcAsTwerVOUzlZwNE5+bo/kdGNQok=; b=c9JYNQoYazxNuvMbfPIly55csjmGzwHixbvu/wBwgzoWdUoZvBoNB5HvKB8O0cIxwv PQUPg4PT+ZAt6P8j/5VO2i1MV2PGpY83Qwr1aVfZiS0NL9VZi6M9FTJ3ix7J37RTbzFR XMEa7o2parQHe2RLMS31QluEQZ9rp/iU/02xsdDEJdmNAPLJtyXV8LieNnTFiX2ebyxl wMUm2WxFzAawehdNS125BOPeZLHmQEL8Tq2GjiXfSf0ege51mhmHfipo15dch8rO8vah 2T4hVRHRL2kqsKU2X5FHxc5UyJ+ziSW5h5WBA2M4Y8lLVeatoOwhy8Ky3WHesIxpBOJ8 o7iw== X-Gm-Message-State: ALoCoQl7AiPVhnBJkssIzOf8Yl6/QOYcuCwpAFChtPCaYxJPgb/0OMIN4Xa+Ss+1RzkLafg35Lap X-Received: by 10.112.130.8 with SMTP id oa8mr1282299lbb.11.1416484480725; Thu, 20 Nov 2014 03:54:40 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.161.203 with SMTP id xu11ls51643lab.90.gmail; Thu, 20 Nov 2014 03:54:40 -0800 (PST) X-Received: by 10.112.16.39 with SMTP id c7mr47092384lbd.19.1416484480458; Thu, 20 Nov 2014 03:54:40 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id i3si1981909lae.59.2014.11.20.03.54.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 03:54:40 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id b6so2101912lbj.2 for ; Thu, 20 Nov 2014 03:54:40 -0800 (PST) X-Received: by 10.112.45.102 with SMTP id l6mr10825576lbm.46.1416484480378; Thu, 20 Nov 2014 03:54:40 -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 ew9csp246801lbc; Thu, 20 Nov 2014 03:54:39 -0800 (PST) X-Received: by 10.224.39.10 with SMTP id d10mr15915856qae.29.1416484479001; Thu, 20 Nov 2014 03:54:39 -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 y4si2433681qgd.71.2014.11.20.03.54.38 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Nov 2014 03:54:38 -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 1XrQJo-000197-Qv; Thu, 20 Nov 2014 11:54:36 +0000 Received: from mail-la0-f47.google.com ([209.85.215.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XrQJT-00015E-92 for lng-odp@lists.linaro.org; Thu, 20 Nov 2014 11:54:15 +0000 Received: by mail-la0-f47.google.com with SMTP id hz20so2288257lab.34 for ; Thu, 20 Nov 2014 03:54:09 -0800 (PST) X-Received: by 10.112.130.65 with SMTP id oc1mr34699922lbb.7.1416484449763; Thu, 20 Nov 2014 03:54:09 -0800 (PST) Received: from macmini.lan (84-217-193-77.tn.glocalnet.net. [84.217.193.77]) by mx.google.com with ESMTPSA id bb3sm534566lab.7.2014.11.20.03.54.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Nov 2014 03:54:09 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 20 Nov 2014 12:53:46 +0100 Message-Id: <1416484428-23849-6-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416484428-23849-1-git-send-email-ola.liljedahl@linaro.org> References: <1416484428-23849-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 5/7] linux-generic: odp_rwlock.c: use odp_atomic.h and GCC __atomic (tmp) 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.217.171 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 --- platform/linux-generic/odp_rwlock.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/platform/linux-generic/odp_rwlock.c b/platform/linux-generic/odp_rwlock.c index 11c8dd7..2f6a255 100644 --- a/platform/linux-generic/odp_rwlock.c +++ b/platform/linux-generic/odp_rwlock.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include #include #include @@ -26,15 +27,18 @@ void odp_rwlock_read_lock(odp_rwlock_t *rwlock) odp_spin(); continue; } - is_locked = odp_atomic_cmpset_u32( - (volatile uint32_t *)&rwlock->cnt, - cnt, cnt + 1); + is_locked = __atomic_compare_exchange_n(&rwlock->cnt, + &cnt, + cnt + 1, + false/*strong*/, + __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } } void odp_rwlock_read_unlock(odp_rwlock_t *rwlock) { - odp_atomic_dec_u32((odp_atomic_u32_t *)(intptr_t)&rwlock->cnt); + (void)__atomic_sub_fetch(&rwlock->cnt, 1, __ATOMIC_RELEASE); } void odp_rwlock_write_lock(odp_rwlock_t *rwlock) @@ -43,19 +47,23 @@ void odp_rwlock_write_lock(odp_rwlock_t *rwlock) int is_locked = 0; while (is_locked == 0) { + int32_t zero = 0; cnt = rwlock->cnt; /* lock aquired, wait */ if (cnt != 0) { odp_spin(); continue; } - is_locked = odp_atomic_cmpset_u32( - (volatile uint32_t *)&rwlock->cnt, - 0, -1); + is_locked = __atomic_compare_exchange_n(&rwlock->cnt, + &zero, + -1, + false/*strong*/, + __ATOMIC_ACQUIRE, + __ATOMIC_RELAXED); } } void odp_rwlock_write_unlock(odp_rwlock_t *rwlock) { - odp_atomic_inc_u32((odp_atomic_u32_t *)(intptr_t)&rwlock->cnt); + (void)__atomic_add_fetch(&rwlock->cnt, 1, __ATOMIC_RELEASE); }