vhost: use loop instead of goto
authorHuawei Xie <huawei.xie@intel.com>
Fri, 6 Mar 2015 05:52:43 +0000 (13:52 +0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Mon, 9 Mar 2015 11:46:46 +0000 (12:46 +0100)
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>
lib/librte_vhost/vhost_user/fd_man.c

index a89b6fe..831c9c1 100644 (file)
@@ -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);
 }
 
 /**