From: Huawei Xie Date: Fri, 6 Mar 2015 05:52:27 +0000 (+0800) Subject: vhost: combine select with sleep X-Git-Tag: spdx-start~9482 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=31ff0c6a45cfc729fd7003d887fcd2612c3aca6d;p=dpdk.git vhost: combine select with sleep combine sleep into select when there is no file descriptors to be monitored. Signed-off-by: Huawei Xie Acked-by: Konstantin Ananyev --- diff --git a/lib/librte_vhost/vhost_user/fd_man.c b/lib/librte_vhost/vhost_user/fd_man.c index 63ac4df0ca..a89b6fea18 100644 --- a/lib/librte_vhost/vhost_user/fd_man.c +++ b/lib/librte_vhost/vhost_user/fd_man.c @@ -211,25 +211,26 @@ fdset_event_dispatch(struct fdset *pfdset) void *dat; int fd; int remove1, remove2; + int ret; if (pfdset == NULL) return; while (1) { + struct timeval tv; + tv.tv_sec = 1; + tv.tv_usec = 0; FD_ZERO(&rfds); FD_ZERO(&wfds); pthread_mutex_lock(&pfdset->fd_mutex); maxfds = fdset_fill(&rfds, &wfds, pfdset); - if (maxfds == -1) { - pthread_mutex_unlock(&pfdset->fd_mutex); - sleep(1); - continue; - } pthread_mutex_unlock(&pfdset->fd_mutex); - select(maxfds + 1, &rfds, &wfds, NULL, NULL); + ret = select(maxfds + 1, &rfds, &wfds, NULL, &tv); + if (ret <= 0) + continue; for (i = 0; i < num; i++) { remove1 = remove2 = 0;