[dpdk-dev] lib/librte_vhost: use loop instead of goto

Message ID 1425621163-14942-1-git-send-email-huawei.xie@intel.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Huawei Xie March 6, 2015, 5:52 a.m. UTC
This patch reorder the code a bit to use loop instead of goto.
Besides, remove abudant check 'fd != -1'.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
 lib/librte_vhost/vhost_user/fd_man.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)
  

Comments

Ananyev, Konstantin March 6, 2015, 10:04 a.m. UTC | #1
> -----Original Message-----
> From: Xie, Huawei
> Sent: Friday, March 06, 2015 5:53 AM
> To: dev@dpdk.org
> Cc: Ananyev, Konstantin; Xie, Huawei
> Subject: [PATCH] lib/librte_vhost: use loop instead of goto
> 
> This patch reorder the code a bit to use loop instead of goto.
> Besides, remove abudant check 'fd != -1'.

Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

> 
> Signed-off-by: Huawei Xie <huawei.xie@intel.com>
> ---
>  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);
>  }
> 
>  /**
> --
> 1.8.1.4
  
Thomas Monjalon March 9, 2015, 8:28 a.m. UTC | #2
> > This patch reorder the code a bit to use loop instead of goto.
> > Besides, remove abudant check 'fd != -1'.
> > 
> > Signed-off-by: Huawei Xie <huawei.xie@intel.com>
> 
> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

Applied, thanks
  

Patch

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);
 }
 
 /**