From 7b53c036e6bf56623b8273018ff1c8cc62847857 Mon Sep 17 00:00:00 2001 From: Ricardo Salveti Date: Mon, 25 Jul 2016 13:22:22 -0300 Subject: Imported Upstream version 16.07-rc4 Change-Id: Ic57f6a3726f2dbd1682223648d91310f45705327 Signed-off-by: Ricardo Salveti --- lib/librte_vhost/vhost_user/fd_man.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/librte_vhost/vhost_user/fd_man.c') diff --git a/lib/librte_vhost/vhost_user/fd_man.c b/lib/librte_vhost/vhost_user/fd_man.c index c691339a..2d3eeb7d 100644 --- a/lib/librte_vhost/vhost_user/fd_man.c +++ b/lib/librte_vhost/vhost_user/fd_man.c @@ -132,8 +132,10 @@ fdset_init(struct fdset *pfdset) if (pfdset == NULL) return; - for (i = 0; i < MAX_FDS; i++) + for (i = 0; i < MAX_FDS; i++) { pfdset->fd[i].fd = -1; + pfdset->fd[i].dat = NULL; + } pfdset->num = 0; } @@ -166,14 +168,16 @@ fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat) /** * Unregister the fd from the fdset. + * Returns context of a given fd or NULL. */ -void +void * fdset_del(struct fdset *pfdset, int fd) { int i; + void *dat = NULL; if (pfdset == NULL || fd == -1) - return; + return NULL; do { pthread_mutex_lock(&pfdset->fd_mutex); @@ -181,13 +185,17 @@ fdset_del(struct fdset *pfdset, int fd) i = fdset_find_fd(pfdset, fd); if (i != -1 && pfdset->fd[i].busy == 0) { /* busy indicates r/wcb is executing! */ + dat = pfdset->fd[i].dat; pfdset->fd[i].fd = -1; pfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL; + pfdset->fd[i].dat = NULL; pfdset->num--; i = -1; } pthread_mutex_unlock(&pfdset->fd_mutex); } while (i != -1); + + return dat; } /** @@ -203,6 +211,7 @@ fdset_del_slot(struct fdset *pfdset, int index) pfdset->fd[index].fd = -1; pfdset->fd[index].rcb = pfdset->fd[index].wcb = NULL; + pfdset->fd[index].dat = NULL; pfdset->num--; pthread_mutex_unlock(&pfdset->fd_mutex); -- cgit 1.2.3-korg