X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_vhost%2Ffd_man.c;h=4c6fed41899981b64bb8fdc5799735a4c661aa98;hb=c1734807fcf9f58a82174d38832382c8f8085ab7;hp=8a075da224a25278fee4c26c5e7fe062362f048e;hpb=59317cef249c0b23098543df527b3e360ce9764f;p=dpdk.git diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c index 8a075da224..4c6fed4189 100644 --- a/lib/librte_vhost/fd_man.c +++ b/lib/librte_vhost/fd_man.c @@ -65,17 +65,12 @@ fdset_move(struct fdset *pfdset, int dst, int src) pfdset->rwfds[dst] = pfdset->rwfds[src]; } -/* - * Find deleted fd entries and remove them - */ static void -fdset_shrink(struct fdset *pfdset) +fdset_shrink_nolock(struct fdset *pfdset) { int i; int last_valid_idx = get_last_valid_idx(pfdset, pfdset->num - 1); - pthread_mutex_lock(&pfdset->fd_mutex); - for (i = 0; i < last_valid_idx; i++) { if (pfdset->fd[i].fd != -1) continue; @@ -84,7 +79,16 @@ fdset_shrink(struct fdset *pfdset) last_valid_idx = get_last_valid_idx(pfdset, last_valid_idx - 1); } pfdset->num = last_valid_idx + 1; +} +/* + * Find deleted fd entries and remove them + */ +static void +fdset_shrink(struct fdset *pfdset) +{ + pthread_mutex_lock(&pfdset->fd_mutex); + fdset_shrink_nolock(pfdset); pthread_mutex_unlock(&pfdset->fd_mutex); } @@ -151,8 +155,12 @@ fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat) pthread_mutex_lock(&pfdset->fd_mutex); i = pfdset->num < MAX_FDS ? pfdset->num++ : -1; if (i == -1) { - pthread_mutex_unlock(&pfdset->fd_mutex); - return -2; + fdset_shrink_nolock(pfdset); + i = pfdset->num < MAX_FDS ? pfdset->num++ : -1; + if (i == -1) { + pthread_mutex_unlock(&pfdset->fd_mutex); + return -2; + } } fdset_add_fd(pfdset, i, fd, rcb, wcb, dat); @@ -202,8 +210,8 @@ fdset_del(struct fdset *pfdset, int fd) * will wait until the flag is reset to zero(which indicates the callback is * finished), then it could free the context after fdset_del. */ -void -fdset_event_dispatch(struct fdset *pfdset) +void * +fdset_event_dispatch(void *arg) { int i; struct pollfd *pfd; @@ -213,9 +221,11 @@ fdset_event_dispatch(struct fdset *pfdset) int fd, numfds; int remove1, remove2; int need_shrink; + struct fdset *pfdset = arg; + int val; if (pfdset == NULL) - return; + return NULL; while (1) { @@ -230,7 +240,9 @@ fdset_event_dispatch(struct fdset *pfdset) numfds = pfdset->num; pthread_mutex_unlock(&pfdset->fd_mutex); - poll(pfdset->rwfds, numfds, 1000 /* millisecs */); + val = poll(pfdset->rwfds, numfds, 1000 /* millisecs */); + if (val < 0) + continue; need_shrink = 0; for (i = 0; i < numfds; i++) { @@ -286,4 +298,6 @@ fdset_event_dispatch(struct fdset *pfdset) if (need_shrink) fdset_shrink(pfdset); } + + return NULL; }