From bb747268ed89af8f034132fa46e30998b72a7ba9 Mon Sep 17 00:00:00 2001 From: Louai Al-Khanji Date: Wed, 3 Feb 2016 19:09:00 -0800 Subject: Clean up new poll code slightly Change-Id: I046126ff69a77a50e79efb1b6ebb0fffef67ac8e Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcore_unix.cpp | 14 -------------- src/corelib/kernel/qcore_unix_p.h | 19 ++++++++++++++++++- src/corelib/kernel/qeventdispatcher_unix.cpp | 10 ++-------- 3 files changed, 20 insertions(+), 23 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index c82754db82..23b98430bc 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -184,18 +184,4 @@ int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout } } -int qt_poll_msecs(pollfd *fds, nfds_t nfds, int timeout) -{ - timespec ts, *pts = Q_NULLPTR; - - if (timeout >= 0) { - ts.tv_sec = timeout / 1000; - ts.tv_nsec = (timeout % 1000) * 1000 * 1000; - - pts = &ts; - } - - return qt_safe_poll(fds, nfds, pts); -} - QT_END_NAMESPACE diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index 9ceee17055..96f791698f 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -326,7 +326,24 @@ void qt_nanosleep(timespec amount); Q_CORE_EXPORT int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts); -int qt_poll_msecs(struct pollfd *fds, nfds_t nfds, int timeout); +static inline int qt_poll_msecs(struct pollfd *fds, nfds_t nfds, int timeout) +{ + timespec ts, *pts = Q_NULLPTR; + + if (timeout >= 0) { + ts.tv_sec = timeout / 1000; + ts.tv_nsec = (timeout % 1000) * 1000 * 1000; + pts = &ts; + } + + return qt_safe_poll(fds, nfds, pts); +} + +static inline struct pollfd qt_make_pollfd(int fd, short events) +{ + struct pollfd pfd = { fd, events, 0 }; + return pfd; +} Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timespec *tv); diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 1faeb7dc39..64b813bb13 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -89,12 +89,6 @@ static const char *socketType(QSocketNotifier::Type type) Q_UNREACHABLE(); } -static pollfd make_pollfd(int fd, short events) -{ - pollfd pfd = { fd, events, 0 }; - return pfd; -} - QThreadPipe::QThreadPipe() { fds[0] = -1; @@ -173,7 +167,7 @@ bool QThreadPipe::init() pollfd QThreadPipe::prepare() const { - return make_pollfd(fds[0], POLLIN); + return qt_make_pollfd(fds[0], POLLIN); } void QThreadPipe::wakeUp() @@ -491,7 +485,7 @@ bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags) if (include_notifiers) for (auto it = d->socketNotifiers.cbegin(); it != d->socketNotifiers.cend(); ++it) - d->pollfds.append(make_pollfd(it.key(), it.value().events())); + d->pollfds.append(qt_make_pollfd(it.key(), it.value().events())); // This must be last, as it's popped off the end below d->pollfds.append(d->threadPipe.prepare()); -- cgit v1.2.3