From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnIcJ-0003Wd-7I for qemu-devel@nongnu.org; Tue, 28 Apr 2015 23:24:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnIcF-0001Nd-2F for qemu-devel@nongnu.org; Tue, 28 Apr 2015 23:24:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57393) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnIcE-0001NZ-TZ for qemu-devel@nongnu.org; Tue, 28 Apr 2015 23:24:50 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 9774C8E779 for ; Wed, 29 Apr 2015 03:24:50 +0000 (UTC) From: Fam Zheng Date: Wed, 29 Apr 2015 11:24:30 +0800 Message-Id: <1430277871-26761-7-git-send-email-famz@redhat.com> In-Reply-To: <1430277871-26761-1-git-send-email-famz@redhat.com> References: <1430277871-26761-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v4 6/7] poll-glib: Support ppoll List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi Signed-off-by: Fam Zheng --- poll-glib.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/poll-glib.c b/poll-glib.c index 64fde69..23d528d 100644 --- a/poll-glib.c +++ b/poll-glib.c @@ -14,6 +14,9 @@ #include "qemu-common.h" #include "qemu/timer.h" #include "qemu/poll.h" +#if CONFIG_PPOLL +#include +#endif struct QEMUPoll { /* Array of GPollFD for g_poll() */ @@ -42,13 +45,33 @@ void qemu_poll_free(QEMUPoll *qpoll) int qemu_poll(QEMUPoll *qpoll, int64_t timeout_ns) { int i; + void *fds = qpoll->gpollfds->data; + int nfds = qpoll->gpollfds->len; + for (i = 0; i < qpoll->gpollfds->len; i++) { GPollFD *p = &g_array_index(qpoll->gpollfds, GPollFD, i); p->revents = 0; } - return g_poll((GPollFD *)qpoll->gpollfds->data, - qpoll->gpollfds->len, - qemu_timeout_ns_to_ms(timeout_ns)); +#if CONFIG_PPOLL + if (timeout_ns < 0) { + return ppoll(fds, nfds, NULL, NULL); + } else { + struct timespec ts; + int64_t tvsec = timeout_ns / 1000000000LL; + /* Avoid possibly overflowing and specifying a negative number of + * seconds, which would turn a very long timeout into a busy-wait. + */ + if (tvsec > (int64_t)INT32_MAX) { + tvsec = INT32_MAX; + } + ts.tv_sec = tvsec; + ts.tv_nsec = timeout_ns % 1000000000LL; + return ppoll(fds, nfds, &ts, NULL); + } + +#else + return g_poll(data, nfds, qemu_timeout_ns_to_ms(timeout_ns)); +#endif } /* Add an fd to poll. Return -EEXIST if fd already registered. */ -- 1.9.3