From patchwork Thu Nov 27 15:13:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 41629 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5B19A2486D for ; Thu, 27 Nov 2014 15:13:51 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf3151898wgh.1 for ; Thu, 27 Nov 2014 07:13:50 -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=t7IVVy4nEwxvxh/u73ESUDybdceGxE7s7o4wI6KbO0I=; b=hTi/2ekXVxQ2V937sQ78mbiLJ+DLh9ak8ncDkwZOE2g21mHxvt3KUgNChAdjBjwYjX USRQifVzJ7D1Xam+1EV1qnHYnNyeDIHDGnfpCTPuuhz8cfr+Zf6Ow5KICGh9/RZf7Kwh RMJjYC5QjF+prcKiJvQ1Ba2DMBjsqIaHptXPpBYrQn8ZYO06BPhFFH8Kno0jYKtuJAo1 UAwLlNWefgmTK4i20sSstHzh/nxg18iU79jA5jMQ9l/0OyYl1NHilU686fyvxRyHrCan 5pD25L7l+kkmm6m3gKx3kjbas47oRP2ZORfsRW8Dn7uCZ1wOrBvluElEeT7r6S9IjLuy iDnw== X-Gm-Message-State: ALoCoQlI+N3P0GcQI8gFhKR8WrnUNZq8NDj13pYicr8Ym8cL91uu6lEVHo+Kv5QfCLwK+/jHNE/0 X-Received: by 10.112.42.104 with SMTP id n8mr194065lbl.19.1417101230618; Thu, 27 Nov 2014 07:13:50 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.72 with SMTP id b8ls921068laf.2.gmail; Thu, 27 Nov 2014 07:13:50 -0800 (PST) X-Received: by 10.152.121.1 with SMTP id lg1mr39080019lab.28.1417101230354; Thu, 27 Nov 2014 07:13:50 -0800 (PST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id as7si7541040lbc.94.2014.11.27.07.13.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Nov 2014 07:13:50 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id u10so4226736lbd.6 for ; Thu, 27 Nov 2014 07:13:50 -0800 (PST) X-Received: by 10.112.189.10 with SMTP id ge10mr39073876lbc.23.1417101230272; Thu, 27 Nov 2014 07:13:50 -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 ew9csp811798lbc; Thu, 27 Nov 2014 07:13:49 -0800 (PST) X-Received: by 10.224.88.193 with SMTP id b1mr55287368qam.30.1417101228944; Thu, 27 Nov 2014 07:13:48 -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 x109si8778269qge.89.2014.11.27.07.13.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 27 Nov 2014 07:13:48 -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 1Xu0lO-0004l3-K0; Thu, 27 Nov 2014 15:13:46 +0000 Received: from mail-la0-f41.google.com ([209.85.215.41]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xu0kw-0004gk-93 for lng-odp@lists.linaro.org; Thu, 27 Nov 2014 15:13:18 +0000 Received: by mail-la0-f41.google.com with SMTP id gf13so4380976lab.0 for ; Thu, 27 Nov 2014 07:13:12 -0800 (PST) X-Received: by 10.152.5.198 with SMTP id u6mr40559800lau.42.1417101192746; Thu, 27 Nov 2014 07:13:12 -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.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Nov 2014 07:13:12 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 27 Nov 2014 16:13:01 +0100 Message-Id: <1417101181-13500-6-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 5/5] linux-generic: odp_ticketlock.[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.217.175 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_ticketlock.h | 2 +- platform/linux-generic/odp_ticketlock.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/platform/linux-generic/include/api/odp_ticketlock.h b/platform/linux-generic/include/api/odp_ticketlock.h index a3b3ab5..619816e 100644 --- a/platform/linux-generic/include/api/odp_ticketlock.h +++ b/platform/linux-generic/include/api/odp_ticketlock.h @@ -31,7 +31,7 @@ extern "C" { */ typedef struct odp_ticketlock_t { odp_atomic_u32_t next_ticket; /**< @private Next ticket */ - volatile uint32_t cur_ticket; /**< @private Current ticket */ + odp_atomic_u32_t cur_ticket; /**< @private Current ticket */ } odp_ticketlock_t; diff --git a/platform/linux-generic/odp_ticketlock.c b/platform/linux-generic/odp_ticketlock.c index e60f526..6c5e74e 100644 --- a/platform/linux-generic/odp_ticketlock.c +++ b/platform/linux-generic/odp_ticketlock.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -13,7 +14,7 @@ void odp_ticketlock_init(odp_ticketlock_t *ticketlock) { odp_atomic_init_u32(&ticketlock->next_ticket, 0); - ticketlock->cur_ticket = 0; + odp_atomic_init_u32(&ticketlock->cur_ticket, 0); } @@ -23,18 +24,15 @@ void odp_ticketlock_lock(odp_ticketlock_t *ticketlock) ticket = odp_atomic_fetch_inc_u32(&ticketlock->next_ticket); - while (ticket != ticketlock->cur_ticket) + while (ticket != _odp_atomic_u32_load_mm(&ticketlock->cur_ticket, + _ODP_MEMMODEL_ACQ)) odp_spin(); - - __atomic_thread_fence(__ATOMIC_ACQUIRE); } void odp_ticketlock_unlock(odp_ticketlock_t *ticketlock) { - __atomic_thread_fence(__ATOMIC_RELEASE); - - ticketlock->cur_ticket++; + _odp_atomic_u32_add_mm(&ticketlock->cur_ticket, 1, _ODP_MEMMODEL_RLS); #if defined __OCTEON__ odp_sync_stores(); /* SYNCW to flush write buffer */ @@ -44,6 +42,6 @@ void odp_ticketlock_unlock(odp_ticketlock_t *ticketlock) int odp_ticketlock_is_locked(odp_ticketlock_t *ticketlock) { - return ticketlock->cur_ticket != + return odp_atomic_load_u32(&ticketlock->cur_ticket) != odp_atomic_load_u32(&ticketlock->next_ticket); }