From patchwork Fri Mar 6 05:52:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huawei Xie X-Patchwork-Id: 3901 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 890CE5949; Fri, 6 Mar 2015 06:52:52 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 9C9DB5677 for ; Fri, 6 Mar 2015 06:52:50 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 05 Mar 2015 21:52:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,351,1422950400"; d="scan'208";a="676003364" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga001.fm.intel.com with ESMTP; 05 Mar 2015 21:52:49 -0800 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t265qlfG030128; Fri, 6 Mar 2015 13:52:47 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t265qjqO014976; Fri, 6 Mar 2015 13:52:47 +0800 Received: (from hxie5@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t265qjcA014972; Fri, 6 Mar 2015 13:52:45 +0800 From: Huawei Xie To: dev@dpdk.org Date: Fri, 6 Mar 2015 13:52:43 +0800 Message-Id: <1425621163-14942-1-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dpdk-dev] [PATCH] lib/librte_vhost: use loop instead of goto X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch reorder the code a bit to use loop instead of goto. Besides, remove abudant check 'fd != -1'. Signed-off-by: Huawei Xie Acked-by: Konstantin Ananyev --- lib/librte_vhost/vhost_user/fd_man.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/librte_vhost/vhost_user/fd_man.c b/lib/librte_vhost/vhost_user/fd_man.c index a89b6fe..831c9c1 100644 --- a/lib/librte_vhost/vhost_user/fd_man.c +++ b/lib/librte_vhost/vhost_user/fd_man.c @@ -172,23 +172,19 @@ fdset_del(struct fdset *pfdset, int fd) if (pfdset == NULL || fd == -1) return; -again: - pthread_mutex_lock(&pfdset->fd_mutex); + do { + pthread_mutex_lock(&pfdset->fd_mutex); - i = fdset_find_fd(pfdset, fd); - if (i != -1 && fd != -1) { - /* busy indicates r/wcb is executing! */ - if (pfdset->fd[i].busy == 1) { - pthread_mutex_unlock(&pfdset->fd_mutex); - goto again; + i = fdset_find_fd(pfdset, fd); + if (i != -1 && pfdset->fd[i].busy == 0) { + /* busy indicates r/wcb is executing! */ + pfdset->fd[i].fd = -1; + pfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL; + pfdset->num--; + i = -1; } - - pfdset->fd[i].fd = -1; - pfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL; - pfdset->num--; - } - - pthread_mutex_unlock(&pfdset->fd_mutex); + pthread_mutex_unlock(&pfdset->fd_mutex); + } while (i != -1); } /**