aboutsummaryrefslogtreecommitdiffstats
path: root/lib/librte_vhost/fd_man.c
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@gmail.com>2018-07-24 16:54:23 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2018-07-24 16:54:26 +0100
commitba78d0104e4ce61135ffb26a39dac0d57b00824b (patch)
treeaeaa93c3b7febdc8bfa46510d93dd05c0e3747d3 /lib/librte_vhost/fd_man.c
parent6fce689301aa6be62eb0786519ff1eaf27bf00c8 (diff)
parent43192222b329b3c984687235b0081c7fbfe484ba (diff)
Merge branch 'upstream-16.11-stable' into 16.11.x
Change-Id: I63e43d3cdc0ac549e2ff917005ccaeec9787b89e Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Diffstat (limited to 'lib/librte_vhost/fd_man.c')
-rw-r--r--lib/librte_vhost/fd_man.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
index 8a075da2..b76b8bce 100644
--- a/lib/librte_vhost/fd_man.c
+++ b/lib/librte_vhost/fd_man.c
@@ -192,6 +192,38 @@ fdset_del(struct fdset *pfdset, int fd)
return dat;
}
+/**
+ * Unregister the fd from the fdset.
+ *
+ * If parameters are invalid, return directly -2.
+ * And check whether fd is busy, if yes, return -1.
+ * Otherwise, try to delete the fd from fdset and
+ * return true.
+ */
+int
+fdset_try_del(struct fdset *pfdset, int fd)
+{
+ int i;
+
+ if (pfdset == NULL || fd == -1)
+ return -2;
+
+ pthread_mutex_lock(&pfdset->fd_mutex);
+ i = fdset_find_fd(pfdset, fd);
+ if (i != -1 && pfdset->fd[i].busy) {
+ pthread_mutex_unlock(&pfdset->fd_mutex);
+ return -1;
+ }
+
+ if (i != -1) {
+ pfdset->fd[i].fd = -1;
+ pfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL;
+ pfdset->fd[i].dat = NULL;
+ }
+
+ pthread_mutex_unlock(&pfdset->fd_mutex);
+ return 0;
+}
/**
* This functions runs in infinite blocking loop until there is no fd in
@@ -275,7 +307,7 @@ fdset_event_dispatch(struct fdset *pfdset)
* because the fd is closed in the cb,
* the old fd val could be reused by when creates new
* listen fd in another thread, we couldn't call
- * fd_set_del.
+ * fdset_del.
*/
if (remove1 || remove2) {
pfdentry->fd = -1;