From patchwork Wed Apr 26 17:00:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 98269 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp421037qgf; Wed, 26 Apr 2017 10:00:27 -0700 (PDT) X-Received: by 10.55.104.132 with SMTP id d126mr762451qkc.31.1493226027313; Wed, 26 Apr 2017 10:00:27 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z127si797966qke.40.2017.04.26.10.00.27; Wed, 26 Apr 2017 10:00:27 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id DDC8760EF6; Wed, 26 Apr 2017 17:00:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id D4EDD60C36; Wed, 26 Apr 2017 17:00:20 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1E79C60CE4; Wed, 26 Apr 2017 17:00:18 +0000 (UTC) Received: from forward11j.cmail.yandex.net (forward11j.cmail.yandex.net [5.255.227.175]) by lists.linaro.org (Postfix) with ESMTPS id B8BBA60C30 for ; Wed, 26 Apr 2017 17:00:15 +0000 (UTC) Received: from smtp1h.mail.yandex.net (smtp1h.mail.yandex.net [84.201.187.144]) by forward11j.cmail.yandex.net (Yandex) with ESMTP id 2638A21BE6 for ; Wed, 26 Apr 2017 20:00:14 +0300 (MSK) Received: from smtp1h.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp1h.mail.yandex.net (Yandex) with ESMTP id B3B158C0EC2 for ; Wed, 26 Apr 2017 20:00:12 +0300 (MSK) Received: by smtp1h.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id NHG5U6Wroj-0BBGgGpx; Wed, 26 Apr 2017 20:00:11 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 26 Apr 2017 20:00:06 +0300 Message-Id: <1493226006-7600-1-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 Github-pr-num: 19 Subject: [lng-odp] [PATCH] linux-generic: rwlock: fix odp_rwlock_read_trylock() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov odp_rwlock_read_trylock() currently works only if there are no readers (and writers) as it compares counter with 0. Make it actually work in case there are other active readers. Fixes: https://bugs.linaro.org/show_bug.cgi?id=2974 Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 19 (lumag:fix-rwlock) ** https://github.com/Linaro/odp/pull/19 ** Patch: https://github.com/Linaro/odp/pull/19.patch ** Base sha: 9b993a1531c94782b48292adff54a95de9d2be5c ** Merge commit sha: 3af3b11b695d157ce1649955b52e8a165cc82937 **/ platform/linux-generic/odp_rwlock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/odp_rwlock.c b/platform/linux-generic/odp_rwlock.c index 13c17a2..e0c46ce 100644 --- a/platform/linux-generic/odp_rwlock.c +++ b/platform/linux-generic/odp_rwlock.c @@ -33,9 +33,9 @@ void odp_rwlock_read_lock(odp_rwlock_t *rwlock) int odp_rwlock_read_trylock(odp_rwlock_t *rwlock) { - uint32_t zero = 0; + uint32_t cnt = odp_atomic_load_u32(&rwlock->cnt); - return odp_atomic_cas_acq_u32(&rwlock->cnt, &zero, (uint32_t)1); + return odp_atomic_cas_acq_u32(&rwlock->cnt, &cnt, cnt + 1); } void odp_rwlock_read_unlock(odp_rwlock_t *rwlock)