From patchwork Mon Nov 24 22:38:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41437 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 E4F9225E18 for ; Mon, 24 Nov 2014 22:39:28 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id u10sf3699676lbd.10 for ; Mon, 24 Nov 2014 14:39:27 -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=wmri6CQUFQE+Agm1Cn2ac/eQpVbZ/mUmoCM9rt55mIY=; b=IEMMy/DWptwi4PUmnvsd6QjmQ8+pO8MRbiy/7dNrYmevdw18zlvY3vwJl/G0gA/0cy po4whpmljhjP+66vI+ArgPk6fldTZVs8rAh0rvqUKvsuRxCc/ZiChMKMY+pT1glyNEqM V4ATxxurSY/RRtkkM7ebtUXY4jrQ8nWmSVMFRGwZ/XeRYg7aoL3auFMfOrGDiIiEuEOJ at8OxSo90hAkC1RO8ae1tuvQ7ECrQpwY1F8swNs03gS5CGrGU/xO86W7KJE6zjCO8RU+ jioksLH8Mb+wRNYOp2XP6yiA+Z/SDldsJ1bxt/bH6T51kx9hluZqhr5VDRgtaq+58sM8 Tu1A== X-Gm-Message-State: ALoCoQmLf82v8AcfKxukP+6FKAcRYMXs9+lV8DdyUModoiZLMEaR1WfrQW/y+XaT1h5T8wKxJhQY X-Received: by 10.152.8.67 with SMTP id p3mr6753400laa.4.1416868767942; Mon, 24 Nov 2014 14:39:27 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.225 with SMTP id y1ls17309lae.25.gmail; Mon, 24 Nov 2014 14:39:27 -0800 (PST) X-Received: by 10.152.216.167 with SMTP id or7mr21600926lac.93.1416868767803; Mon, 24 Nov 2014 14:39:27 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id r2si16629831lar.2.2014.11.24.14.39.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Nov 2014 14:39:27 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id q1so8340984lam.39 for ; Mon, 24 Nov 2014 14:39:27 -0800 (PST) X-Received: by 10.152.37.69 with SMTP id w5mr22450903laj.67.1416868767454; Mon, 24 Nov 2014 14:39:27 -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 ew9csp348164lbc; Mon, 24 Nov 2014 14:39:26 -0800 (PST) X-Received: by 10.220.103.74 with SMTP id j10mr4548564vco.58.1416868765598; Mon, 24 Nov 2014 14:39:25 -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 ea2si6959167vdb.13.2014.11.24.14.39.24 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 24 Nov 2014 14:39:25 -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 1Xt2Hz-0007pL-Ah; Mon, 24 Nov 2014 22:39:23 +0000 Received: from mail-lb0-f176.google.com ([209.85.217.176]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xt2Hh-0007lz-LA for lng-odp@lists.linaro.org; Mon, 24 Nov 2014 22:39:05 +0000 Received: by mail-lb0-f176.google.com with SMTP id p9so7389928lbv.35 for ; Mon, 24 Nov 2014 14:39:00 -0800 (PST) X-Received: by 10.112.25.73 with SMTP id a9mr23490525lbg.10.1416868739955; Mon, 24 Nov 2014 14:38:59 -0800 (PST) Received: from macmini.lan (84-217-193-77.tn.glocalnet.net. [84.217.193.77]) by mx.google.com with ESMTPSA id pr9sm2952957lbc.12.2014.11.24.14.38.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Nov 2014 14:38:59 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Mon, 24 Nov 2014 23:38:43 +0100 Message-Id: <1416868730-26140-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416868730-26140-1-git-send-email-ola.liljedahl@linaro.org> References: <1416868730-26140-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH v3 2/9] linux-generic: odp_rwlock.c use __atomic 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.52 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 --- Updated to use GCC __atomic facilities (temporary fix). 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); }