diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_unix.cpp | 37 | ||||
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_unix_p.h | 3 |
2 files changed, 36 insertions, 4 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 995f5101cb..6408147567 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -56,6 +56,10 @@ #include <stdio.h> #include <stdlib.h> +#ifndef QT_NO_EVENTFD +# include <sys/eventfd.h> +#endif + // VxWorks doesn't correctly set the _POSIX_... options #if defined(Q_OS_VXWORKS) # if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK <= 0) @@ -127,6 +131,12 @@ QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate() } } #else +# ifndef QT_NO_EVENTFD + thread_pipe[0] = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + if (thread_pipe[0] != -1) + thread_pipe[1] = -1; + else // fall through the next "if" +# endif if (qt_safe_pipe(thread_pipe, O_NONBLOCK) == -1) { perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe"); pipefail = true; @@ -155,7 +165,8 @@ QEventDispatcherUNIXPrivate::~QEventDispatcherUNIXPrivate() #else // cleanup the common parts of the event loop close(thread_pipe[0]); - close(thread_pipe[1]); + if (thread_pipe[1] != -1) + close(thread_pipe[1]); #endif // cleanup timers @@ -279,9 +290,18 @@ int QEventDispatcherUNIXPrivate::processThreadWakeUp(int nsel) ::read(thread_pipe[0], c, sizeof(c)); ::ioctl(thread_pipe[0], FIOFLUSH, 0); #else - char c[16]; - while (::read(thread_pipe[0], c, sizeof(c)) > 0) - ; +# ifndef QT_NO_EVENTFD + if (thread_pipe[1] == -1) { + // eventfd + eventfd_t value; + eventfd_read(thread_pipe[0], &value); + } else +# endif + { + char c[16]; + while (::read(thread_pipe[0], c, sizeof(c)) > 0) { + } + } #endif if (!wakeUps.testAndSetRelease(1, 0)) { // hopefully, this is dead code @@ -630,6 +650,15 @@ void QEventDispatcherUNIX::wakeUp() { Q_D(QEventDispatcherUNIX); if (d->wakeUps.testAndSetAcquire(0, 1)) { +#ifndef QT_NO_EVENTFD + if (d->thread_pipe[1] == -1) { + // eventfd + eventfd_t value = 1; + int ret; + EINTR_LOOP(ret, eventfd_write(d->thread_pipe[0], value)); + return; + } +#endif char c = 0; qt_safe_write( d->thread_pipe[1], &c, 1 ); } diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h index 98ea19ced8..e96acf65af 100644 --- a/src/corelib/kernel/qeventdispatcher_unix_p.h +++ b/src/corelib/kernel/qeventdispatcher_unix_p.h @@ -148,6 +148,9 @@ public: virtual int processThreadWakeUp(int nsel); bool mainThread; + + // note for eventfd(7) support: + // if thread_pipe[1] is -1, then eventfd(7) is in use and is stored in thread_pipe[0] int thread_pipe[2]; // highest fd for all socket notifiers |