From patchwork Thu Apr 14 16:35:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 65840 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp702967qge; Thu, 14 Apr 2016 09:35:27 -0700 (PDT) X-Received: by 10.55.201.216 with SMTP id m85mr19646777qkl.42.1460651727505; Thu, 14 Apr 2016 09:35:27 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t105si33094194qge.124.2016.04.14.09.35.27; Thu, 14 Apr 2016 09:35: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=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 23AAB685E7; Thu, 14 Apr 2016 16:35:27 +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, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 B2E11684DF; Thu, 14 Apr 2016 16:35:22 +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 B16D1685D9; Thu, 14 Apr 2016 16:35:20 +0000 (UTC) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by lists.linaro.org (Postfix) with ESMTPS id AE2EE62CAA for ; Thu, 14 Apr 2016 16:35:19 +0000 (UTC) Received: by mail-lf0-f50.google.com with SMTP id e190so115690669lfe.0 for ; Thu, 14 Apr 2016 09:35:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FASOlqYbnPUjVobEElyg0wPmXXKJKNXjMjjGbdeoZKA=; b=O2J/PZQzLj7EcsfMnJxnYx0kJ7VIrfWtwxJWU1V1A+2OvbMjmabp5llJdniNxBEGSC NjtKa7x0I4ZQWHMIZHwBE/6yVrUSnh/09cQjo/LCZByGdkHTDVZf2ZDjP09vLpqJAkR4 6kf1aTPNXvI4GvSewnWNFAI8mYWU4+V+VLygENhFVOzId3IXpPN4XTLTYtE8wOscz5CY YHyuOMnBgeOQVI5VRR5JaLBPvVA9DhlP42YXQ0sHAjfWxUDyNAQFg7/Q38YThManzFbB 5AzNxBvHb92QOCAh8us+TU8GeW/vjSuGVgxCvPYD+KqK5caH4vs9114fRXTL+I9xQB0B cyiw== X-Gm-Message-State: AOPr4FWGYhIZ+pJM96XvvPRZnW36dezq+ZDZrnqaBqSoQgJlfFxorHCYVn46LAYuY2XuW81Ym3k= X-Received: by 10.25.150.207 with SMTP id y198mr6823393lfd.76.1460651718665; Thu, 14 Apr 2016 09:35:18 -0700 (PDT) Received: from localhost.localdomain (ppp91-77-173-31.pppoe.mtu-net.ru. [91.77.173.31]) by smtp.gmail.com with ESMTPSA id i1sm6905268lbs.22.2016.04.14.09.35.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Apr 2016 09:35:18 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 14 Apr 2016 19:35:07 +0300 Message-Id: <1460651707-23768-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 X-Topics: patch Subject: [lng-odp] [PATCH] linux-generic: rework odp_queue_create 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" - use odp_config_queues() to get number of queues and int cycle iterrator. That makes it more easy to reuse that function for other platfroms.; - remove declaring variables to invalid at the bottom and check for them down the code; - make code more easy to read; Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_queue.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index 342ffa2..0f7fd15 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -234,10 +234,8 @@ int odp_queue_lock_count(odp_queue_t handle) odp_queue_t odp_queue_create(const char *name, const odp_queue_param_t *param) { - uint32_t i; + int i; queue_entry_t *queue; - odp_queue_t handle = ODP_QUEUE_INVALID; - odp_queue_type_t type; odp_queue_param_t default_param; if (param == NULL) { @@ -245,7 +243,7 @@ odp_queue_t odp_queue_create(const char *name, const odp_queue_param_t *param) param = &default_param; } - for (i = 0; i < ODP_CONFIG_QUEUES; i++) { + for (i = 0; i < odp_config_queues(); i++) { queue = &queue_tbl->queue[i]; if (queue->s.status != QUEUE_STATUS_FREE) @@ -253,33 +251,29 @@ odp_queue_t odp_queue_create(const char *name, const odp_queue_param_t *param) LOCK(&queue->s.lock); if (queue->s.status == QUEUE_STATUS_FREE) { - if (queue_init(queue, name, param)) { + if (queue_init(queue, name, param) || + queue->s.handle == ODP_QUEUE_INVALID) { UNLOCK(&queue->s.lock); - return handle; + return ODP_QUEUE_INVALID; } - type = queue->s.type; - - if (type == ODP_QUEUE_TYPE_SCHED) + if (queue->s.type == ODP_QUEUE_TYPE_SCHED) { queue->s.status = QUEUE_STATUS_NOTSCHED; - else + if (schedule_queue_init(queue)) { + ODP_ERR("schedule queue init failed\n"); + UNLOCK(&queue->s.lock); + return ODP_QUEUE_INVALID; + } + } else { queue->s.status = QUEUE_STATUS_READY; - - handle = queue->s.handle; + } UNLOCK(&queue->s.lock); - break; + return queue->s.handle; } UNLOCK(&queue->s.lock); } - if (handle != ODP_QUEUE_INVALID && type == ODP_QUEUE_TYPE_SCHED) { - if (schedule_queue_init(queue)) { - ODP_ERR("schedule queue init failed\n"); - return ODP_QUEUE_INVALID; - } - } - - return handle; + return ODP_QUEUE_INVALID; } void queue_destroy_finalize(queue_entry_t *queue)