From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YibsH-0005KE-E5 for qemu-devel@nongnu.org; Thu, 16 Apr 2015 00:58:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YibsG-0003Gz-Hh for qemu-devel@nongnu.org; Thu, 16 Apr 2015 00:58:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40071) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YibsG-0003Gk-98 for qemu-devel@nongnu.org; Thu, 16 Apr 2015 00:58:00 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3G4vxZ7000813 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 16 Apr 2015 00:57:59 -0400 From: Fam Zheng Date: Thu, 16 Apr 2015 12:57:35 +0800 Message-Id: <1429160256-27231-7-git-send-email-famz@redhat.com> In-Reply-To: <1429160256-27231-1-git-send-email-famz@redhat.com> References: <1429160256-27231-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v3 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