* [PATCH] lib/librte_vhost: use loop instead of goto
@ 2015-03-06 5:52 Huawei Xie
[not found] ` <1425621163-14942-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Huawei Xie @ 2015-03-06 5:52 UTC (permalink / raw)
To: dev-VfR2kkLFssw
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-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lib/librte_vhost: use loop instead of goto
[not found] ` <1425621163-14942-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2015-03-06 10:04 ` Ananyev, Konstantin
[not found] ` <2601191342CEEE43887BDE71AB977258213F448B-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Ananyev, Konstantin @ 2015-03-06 10:04 UTC (permalink / raw)
To: Xie, Huawei, dev-VfR2kkLFssw@public.gmane.org
> -----Original Message-----
> From: Xie, Huawei
> Sent: Friday, March 06, 2015 5:53 AM
> To: dev-VfR2kkLFssw@public.gmane.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-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> Signed-off-by: Huawei Xie <huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> ---
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lib/librte_vhost: use loop instead of goto
[not found] ` <2601191342CEEE43887BDE71AB977258213F448B-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2015-03-09 8:28 ` Thomas Monjalon
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2015-03-09 8:28 UTC (permalink / raw)
To: Xie, Huawei; +Cc: dev-VfR2kkLFssw
> > 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-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> Acked-by: Konstantin Ananyev <konstantin.ananyev-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Applied, thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-09 8:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-06 5:52 [PATCH] lib/librte_vhost: use loop instead of goto Huawei Xie
[not found] ` <1425621163-14942-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-06 10:04 ` Ananyev, Konstantin
[not found] ` <2601191342CEEE43887BDE71AB977258213F448B-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-09 8:28 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).