| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qeventdispatcher_unix.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qplatformdefs.h" | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #include "qcoreapplication.h" | - | ||||||||||||||||||
| 37 | #include "qpair.h" | - | ||||||||||||||||||
| 38 | #include "qsocketnotifier.h" | - | ||||||||||||||||||
| 39 | #include "qthread.h" | - | ||||||||||||||||||
| 40 | #include "qelapsedtimer.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #include "qeventdispatcher_unix_p.h" | - | ||||||||||||||||||
| 43 | #include <private/qthread_p.h> | - | ||||||||||||||||||
| 44 | #include <private/qcoreapplication_p.h> | - | ||||||||||||||||||
| 45 | #include <private/qcore_unix_p.h> | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | #include <errno.h> | - | ||||||||||||||||||
| 48 | #include <stdio.h> | - | ||||||||||||||||||
| 49 | #include <stdlib.h> | - | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | #ifndef QT_NO_EVENTFD | - | ||||||||||||||||||
| 52 | # include <sys/eventfd.h> | - | ||||||||||||||||||
| 53 | #endif | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | // VxWorks doesn't correctly set the _POSIX_... options | - | ||||||||||||||||||
| 56 | #if defined(Q_OS_VXWORKS) | - | ||||||||||||||||||
| 57 | # if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK <= 0) | - | ||||||||||||||||||
| 58 | # undef _POSIX_MONOTONIC_CLOCK | - | ||||||||||||||||||
| 59 | # define _POSIX_MONOTONIC_CLOCK 1 | - | ||||||||||||||||||
| 60 | # endif | - | ||||||||||||||||||
| 61 | # include <pipeDrv.h> | - | ||||||||||||||||||
| 62 | # include <selectLib.h> | - | ||||||||||||||||||
| 63 | #endif | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | #if (_POSIX_MONOTONIC_CLOCK-0 <= 0) || defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||
| 66 | # include <sys/times.h> | - | ||||||||||||||||||
| 67 | #endif | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | #if defined(Q_OS_INTEGRITY) || defined(Q_OS_VXWORKS) | - | ||||||||||||||||||
| 72 | static void initThreadPipeFD(int fd) | - | ||||||||||||||||||
| 73 | { | - | ||||||||||||||||||
| 74 | int ret = fcntl(fd, F_SETFD, FD_CLOEXEC); | - | ||||||||||||||||||
| 75 | if (ret == -1) | - | ||||||||||||||||||
| 76 | perror("QEventDispatcherUNIXPrivate: Unable to init thread pipe"); | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | int flags = fcntl(fd, F_GETFL); | - | ||||||||||||||||||
| 79 | if (flags == -1) | - | ||||||||||||||||||
| 80 | perror("QEventDispatcherUNIXPrivate: Unable to get flags on thread pipe"); | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK); | - | ||||||||||||||||||
| 83 | if (ret == -1) | - | ||||||||||||||||||
| 84 | perror("QEventDispatcherUNIXPrivate: Unable to set flags on thread pipe"); | - | ||||||||||||||||||
| 85 | } | - | ||||||||||||||||||
| 86 | #endif | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate() | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | extern Qt::HANDLE qt_application_thread_id; | - | ||||||||||||||||||
| 91 | mainThread = (QThread::currentThreadId() == qt_application_thread_id); | - | ||||||||||||||||||
| 92 | bool pipefail = false; | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | // initialize the common parts of the event loop | - | ||||||||||||||||||
| 95 | #if defined(Q_OS_NACL) || defined (Q_OS_BLACKBERRY) | - | ||||||||||||||||||
| 96 | // do nothing. | - | ||||||||||||||||||
| 97 | #elif defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||
| 98 | // INTEGRITY doesn't like a "select" on pipes, so use socketpair instead | - | ||||||||||||||||||
| 99 | if (socketpair(AF_INET, SOCK_STREAM, 0, thread_pipe) == -1) { | - | ||||||||||||||||||
| 100 | perror("QEventDispatcherUNIXPrivate(): Unable to create socket pair"); | - | ||||||||||||||||||
| 101 | pipefail = true; | - | ||||||||||||||||||
| 102 | } else { | - | ||||||||||||||||||
| 103 | initThreadPipeFD(thread_pipe[0]); | - | ||||||||||||||||||
| 104 | initThreadPipeFD(thread_pipe[1]); | - | ||||||||||||||||||
| 105 | } | - | ||||||||||||||||||
| 106 | #elif defined(Q_OS_VXWORKS) | - | ||||||||||||||||||
| 107 | char name[20]; | - | ||||||||||||||||||
| 108 | qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdSelf())); | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | // make sure there is no pipe with this name | - | ||||||||||||||||||
| 111 | pipeDevDelete(name, true); | - | ||||||||||||||||||
| 112 | // create the pipe | - | ||||||||||||||||||
| 113 | if (pipeDevCreate(name, 128 /*maxMsg*/, 1 /*maxLength*/) != OK) { | - | ||||||||||||||||||
| 114 | perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe device"); | - | ||||||||||||||||||
| 115 | pipefail = true; | - | ||||||||||||||||||
| 116 | } else { | - | ||||||||||||||||||
| 117 | if ((thread_pipe[0] = open(name, O_RDWR, 0)) < 0) { | - | ||||||||||||||||||
| 118 | perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe"); | - | ||||||||||||||||||
| 119 | pipefail = true; | - | ||||||||||||||||||
| 120 | } else { | - | ||||||||||||||||||
| 121 | initThreadPipeFD(thread_pipe[0]); | - | ||||||||||||||||||
| 122 | thread_pipe[1] = thread_pipe[0]; | - | ||||||||||||||||||
| 123 | } | - | ||||||||||||||||||
| 124 | } | - | ||||||||||||||||||
| 125 | #else | - | ||||||||||||||||||
| 126 | # ifndef QT_NO_EVENTFD | - | ||||||||||||||||||
| 127 | thread_pipe[0] = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); | - | ||||||||||||||||||
| 128 | if (thread_pipe[0] != -1)
| 0 | ||||||||||||||||||
| 129 | thread_pipe[1] = -1; never executed: thread_pipe[1] = -1; | 0 | ||||||||||||||||||
| 130 | else // fall through the next "if" | - | ||||||||||||||||||
| 131 | # endif | - | ||||||||||||||||||
| 132 | if (qt_safe_pipe(thread_pipe, O_NONBLOCK) == -1) {
| 0 | ||||||||||||||||||
| 133 | perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe"); | - | ||||||||||||||||||
| 134 | pipefail = true; | - | ||||||||||||||||||
| 135 | } never executed: end of block | 0 | ||||||||||||||||||
| 136 | #endif | - | ||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | if (pipefail)
| 0 | ||||||||||||||||||
| 139 | qFatal("QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe"); never executed: QMessageLogger(__FILE__, 139, __PRETTY_FUNCTION__).fatal("QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe"); | 0 | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | sn_highest = -1; | - | ||||||||||||||||||
| 142 | } never executed: end of block | 0 | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | QEventDispatcherUNIXPrivate::~QEventDispatcherUNIXPrivate() | - | ||||||||||||||||||
| 145 | { | - | ||||||||||||||||||
| 146 | #if defined(Q_OS_NACL) || defined (Q_OS_BLACKBERRY) | - | ||||||||||||||||||
| 147 | // do nothing. | - | ||||||||||||||||||
| 148 | #elif defined(Q_OS_VXWORKS) | - | ||||||||||||||||||
| 149 | close(thread_pipe[0]); | - | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | char name[20]; | - | ||||||||||||||||||
| 152 | qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdSelf())); | - | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | pipeDevDelete(name, true); | - | ||||||||||||||||||
| 155 | #else | - | ||||||||||||||||||
| 156 | // cleanup the common parts of the event loop | - | ||||||||||||||||||
| 157 | close(thread_pipe[0]); | - | ||||||||||||||||||
| 158 | if (thread_pipe[1] != -1)
| 0 | ||||||||||||||||||
| 159 | close(thread_pipe[1]); never executed: close(thread_pipe[1]); | 0 | ||||||||||||||||||
| 160 | #endif | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | // cleanup timers | - | ||||||||||||||||||
| 163 | qDeleteAll(timerList); | - | ||||||||||||||||||
| 164 | } never executed: end of block | 0 | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags, timespec *timeout) | - | ||||||||||||||||||
| 167 | { | - | ||||||||||||||||||
| 168 | Q_Q(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | // needed in QEventDispatcherUNIX::select() | - | ||||||||||||||||||
| 171 | timerList.updateCurrentTime(); | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | int nsel; | - | ||||||||||||||||||
| 174 | do { | - | ||||||||||||||||||
| 175 | // Process timers and socket notifiers - the common UNIX stuff | - | ||||||||||||||||||
| 176 | int highest = 0; | - | ||||||||||||||||||
| 177 | if (! (flags & QEventLoop::ExcludeSocketNotifiers) && (sn_highest >= 0)) {
| 0 | ||||||||||||||||||
| 178 | // return the highest fd we can wait for input on | - | ||||||||||||||||||
| 179 | sn_vec[0].select_fds = sn_vec[0].enabled_fds; | - | ||||||||||||||||||
| 180 | sn_vec[1].select_fds = sn_vec[1].enabled_fds; | - | ||||||||||||||||||
| 181 | sn_vec[2].select_fds = sn_vec[2].enabled_fds; | - | ||||||||||||||||||
| 182 | highest = sn_highest; | - | ||||||||||||||||||
| 183 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 184 | FD_ZERO(&sn_vec[0].select_fds); | - | ||||||||||||||||||
| 185 | FD_ZERO(&sn_vec[1].select_fds); | - | ||||||||||||||||||
| 186 | FD_ZERO(&sn_vec[2].select_fds); | - | ||||||||||||||||||
| 187 | } never executed: end of block | 0 | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | int wakeUpFd = initThreadWakeUp(); | - | ||||||||||||||||||
| 190 | highest = qMax(highest, wakeUpFd); | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | nsel = q->select(highest + 1, | - | ||||||||||||||||||
| 193 | &sn_vec[0].select_fds, | - | ||||||||||||||||||
| 194 | &sn_vec[1].select_fds, | - | ||||||||||||||||||
| 195 | &sn_vec[2].select_fds, | - | ||||||||||||||||||
| 196 | timeout); | - | ||||||||||||||||||
| 197 | } while (nsel == -1 && (errno == EINTR || errno == EAGAIN)); never executed: end of block
| 0 | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | if (nsel == -1) {
| 0 | ||||||||||||||||||
| 200 | if (errno == EBADF) {
| 0 | ||||||||||||||||||
| 201 | // it seems a socket notifier has a bad fd... find out | - | ||||||||||||||||||
| 202 | // which one it is and disable it | - | ||||||||||||||||||
| 203 | fd_set fdset; | - | ||||||||||||||||||
| 204 | timeval tm; | - | ||||||||||||||||||
| 205 | tm.tv_sec = tm.tv_usec = 0l; | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | for (int type = 0; type < 3; ++type) {
| 0 | ||||||||||||||||||
| 208 | QSockNotType::List &list = sn_vec[type].list; | - | ||||||||||||||||||
| 209 | if (list.size() == 0)
| 0 | ||||||||||||||||||
| 210 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | for (int i = 0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||
| 213 | QSockNot *sn = list[i]; | - | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | FD_ZERO(&fdset); | - | ||||||||||||||||||
| 216 | FD_SET(sn->fd, &fdset); | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | int ret = -1; | - | ||||||||||||||||||
| 219 | do { | - | ||||||||||||||||||
| 220 | switch (type) { | - | ||||||||||||||||||
| 221 | case 0: // read never executed: case 0: | 0 | ||||||||||||||||||
| 222 | ret = select(sn->fd + 1, &fdset, 0, 0, &tm); | - | ||||||||||||||||||
| 223 | break; never executed: break; | 0 | ||||||||||||||||||
| 224 | case 1: // write never executed: case 1: | 0 | ||||||||||||||||||
| 225 | ret = select(sn->fd + 1, 0, &fdset, 0, &tm); | - | ||||||||||||||||||
| 226 | break; never executed: break; | 0 | ||||||||||||||||||
| 227 | case 2: // except never executed: case 2: | 0 | ||||||||||||||||||
| 228 | ret = select(sn->fd + 1, 0, 0, &fdset, &tm); | - | ||||||||||||||||||
| 229 | break; never executed: break; | 0 | ||||||||||||||||||
| 230 | } | - | ||||||||||||||||||
| 231 | } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); never executed: end of block
| 0 | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | if (ret == -1 && errno == EBADF) {
| 0 | ||||||||||||||||||
| 234 | // disable the invalid socket notifier | - | ||||||||||||||||||
| 235 | static const char *t[] = { "Read", "Write", "Exception" }; | - | ||||||||||||||||||
| 236 | qWarning("QSocketNotifier: Invalid socket %d and type '%s', disabling...", | - | ||||||||||||||||||
| 237 | sn->fd, t[type]); | - | ||||||||||||||||||
| 238 | sn->obj->setEnabled(false); | - | ||||||||||||||||||
| 239 | } never executed: end of block | 0 | ||||||||||||||||||
| 240 | } never executed: end of block | 0 | ||||||||||||||||||
| 241 | } never executed: end of block | 0 | ||||||||||||||||||
| 242 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 243 | // EINVAL... shouldn't happen, so let's complain to stderr | - | ||||||||||||||||||
| 244 | // and hope someone sends us a bug report | - | ||||||||||||||||||
| 245 | perror("select"); | - | ||||||||||||||||||
| 246 | } never executed: end of block | 0 | ||||||||||||||||||
| 247 | } | - | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | int nevents = processThreadWakeUp(nsel); | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | // activate socket notifiers | - | ||||||||||||||||||
| 252 | if (! (flags & QEventLoop::ExcludeSocketNotifiers) && nsel > 0 && sn_highest >= 0) {
| 0 | ||||||||||||||||||
| 253 | // if select says data is ready on any socket, then set the socket notifier | - | ||||||||||||||||||
| 254 | // to pending | - | ||||||||||||||||||
| 255 | for (int i=0; i<3; i++) {
| 0 | ||||||||||||||||||
| 256 | QSockNotType::List &list = sn_vec[i].list; | - | ||||||||||||||||||
| 257 | for (int j = 0; j < list.size(); ++j) {
| 0 | ||||||||||||||||||
| 258 | QSockNot *sn = list[j]; | - | ||||||||||||||||||
| 259 | if (FD_ISSET(sn->fd, &sn_vec[i].select_fds))
| 0 | ||||||||||||||||||
| 260 | q->setSocketNotifierPending(sn->obj); never executed: q->setSocketNotifierPending(sn->obj); | 0 | ||||||||||||||||||
| 261 | } never executed: end of block | 0 | ||||||||||||||||||
| 262 | } never executed: end of block | 0 | ||||||||||||||||||
| 263 | } never executed: end of block | 0 | ||||||||||||||||||
| 264 | return (nevents + q->activateSocketNotifiers()); never executed: return (nevents + q->activateSocketNotifiers()); | 0 | ||||||||||||||||||
| 265 | } | - | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | int QEventDispatcherUNIXPrivate::initThreadWakeUp() | - | ||||||||||||||||||
| 268 | { | - | ||||||||||||||||||
| 269 | FD_SET(thread_pipe[0], &sn_vec[0].select_fds); | - | ||||||||||||||||||
| 270 | return thread_pipe[0]; never executed: return thread_pipe[0]; | 0 | ||||||||||||||||||
| 271 | } | - | ||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | int QEventDispatcherUNIXPrivate::processThreadWakeUp(int nsel) | - | ||||||||||||||||||
| 274 | { | - | ||||||||||||||||||
| 275 | if (nsel > 0 && FD_ISSET(thread_pipe[0], &sn_vec[0].select_fds)) {
| 0 | ||||||||||||||||||
| 276 | // some other thread woke us up... consume the data on the thread pipe so that | - | ||||||||||||||||||
| 277 | // select doesn't immediately return next time | - | ||||||||||||||||||
| 278 | #if defined(Q_OS_VXWORKS) | - | ||||||||||||||||||
| 279 | char c[16]; | - | ||||||||||||||||||
| 280 | ::read(thread_pipe[0], c, sizeof(c)); | - | ||||||||||||||||||
| 281 | ::ioctl(thread_pipe[0], FIOFLUSH, 0); | - | ||||||||||||||||||
| 282 | #else | - | ||||||||||||||||||
| 283 | # ifndef QT_NO_EVENTFD | - | ||||||||||||||||||
| 284 | if (thread_pipe[1] == -1) {
| 0 | ||||||||||||||||||
| 285 | // eventfd | - | ||||||||||||||||||
| 286 | eventfd_t value; | - | ||||||||||||||||||
| 287 | eventfd_read(thread_pipe[0], &value); | - | ||||||||||||||||||
| 288 | } else never executed: end of block | 0 | ||||||||||||||||||
| 289 | # endif | - | ||||||||||||||||||
| 290 | { | - | ||||||||||||||||||
| 291 | char c[16]; | - | ||||||||||||||||||
| 292 | while (::read(thread_pipe[0], c, sizeof(c)) > 0) {
| 0 | ||||||||||||||||||
| 293 | } never executed: end of block | 0 | ||||||||||||||||||
| 294 | } never executed: end of block | 0 | ||||||||||||||||||
| 295 | #endif | - | ||||||||||||||||||
| 296 | if (!wakeUps.testAndSetRelease(1, 0)) {
| 0 | ||||||||||||||||||
| 297 | // hopefully, this is dead code | - | ||||||||||||||||||
| 298 | qWarning("QEventDispatcherUNIX: internal error, wakeUps.testAndSetRelease(1, 0) failed!"); | - | ||||||||||||||||||
| 299 | } never executed: end of block | 0 | ||||||||||||||||||
| 300 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
| 301 | } | - | ||||||||||||||||||
| 302 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 303 | } | - | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | QEventDispatcherUNIX::QEventDispatcherUNIX(QObject *parent) | - | ||||||||||||||||||
| 306 | : QAbstractEventDispatcher(*new QEventDispatcherUNIXPrivate, parent) | - | ||||||||||||||||||
| 307 | { never executed: }end of blocknever executed: end of block | 0 | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | QEventDispatcherUNIX::QEventDispatcherUNIX(QEventDispatcherUNIXPrivate &dd, QObject *parent) | - | ||||||||||||||||||
| 310 | : QAbstractEventDispatcher(dd, parent) | - | ||||||||||||||||||
| 311 | { never executed: }end of blocknever executed: end of block | 0 | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | QEventDispatcherUNIX::~QEventDispatcherUNIX() | - | ||||||||||||||||||
| 314 | { | - | ||||||||||||||||||
| 315 | } | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | int QEventDispatcherUNIX::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, | - | ||||||||||||||||||
| 318 | timespec *timeout) | - | ||||||||||||||||||
| 319 | { | - | ||||||||||||||||||
| 320 | return qt_safe_select(nfds, readfds, writefds, exceptfds, timeout); never executed: return qt_safe_select(nfds, readfds, writefds, exceptfds, timeout); | 0 | ||||||||||||||||||
| 321 | } | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | /*! | - | ||||||||||||||||||
| 324 | \internal | - | ||||||||||||||||||
| 325 | */ | - | ||||||||||||||||||
| 326 | void QEventDispatcherUNIX::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *obj) | - | ||||||||||||||||||
| 327 | { | - | ||||||||||||||||||
| 328 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 329 | if (timerId < 1 || interval < 0 || !obj) {
| 0 | ||||||||||||||||||
| 330 | qWarning("QEventDispatcherUNIX::registerTimer: invalid arguments"); | - | ||||||||||||||||||
| 331 | return; never executed: return; | 0 | ||||||||||||||||||
| 332 | } else if (obj->thread() != thread() || thread() != QThread::currentThread()) {
| 0 | ||||||||||||||||||
| 333 | qWarning("QEventDispatcherUNIX::registerTimer: timers cannot be started from another thread"); | - | ||||||||||||||||||
| 334 | return; never executed: return; | 0 | ||||||||||||||||||
| 335 | } | - | ||||||||||||||||||
| 336 | #endif | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 339 | d->timerList.registerTimer(timerId, interval, timerType, obj); | - | ||||||||||||||||||
| 340 | } never executed: end of block | 0 | ||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | /*! | - | ||||||||||||||||||
| 343 | \internal | - | ||||||||||||||||||
| 344 | */ | - | ||||||||||||||||||
| 345 | bool QEventDispatcherUNIX::unregisterTimer(int timerId) | - | ||||||||||||||||||
| 346 | { | - | ||||||||||||||||||
| 347 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 348 | if (timerId < 1) {
| 0 | ||||||||||||||||||
| 349 | qWarning("QEventDispatcherUNIX::unregisterTimer: invalid argument"); | - | ||||||||||||||||||
| 350 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 351 | } else if (thread() != QThread::currentThread()) {
| 0 | ||||||||||||||||||
| 352 | qWarning("QEventDispatcherUNIX::unregisterTimer: timers cannot be stopped from another thread"); | - | ||||||||||||||||||
| 353 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 354 | } | - | ||||||||||||||||||
| 355 | #endif | - | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 358 | return d->timerList.unregisterTimer(timerId); never executed: return d->timerList.unregisterTimer(timerId); | 0 | ||||||||||||||||||
| 359 | } | - | ||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | /*! | - | ||||||||||||||||||
| 362 | \internal | - | ||||||||||||||||||
| 363 | */ | - | ||||||||||||||||||
| 364 | bool QEventDispatcherUNIX::unregisterTimers(QObject *object) | - | ||||||||||||||||||
| 365 | { | - | ||||||||||||||||||
| 366 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 367 | if (!object) {
| 0 | ||||||||||||||||||
| 368 | qWarning("QEventDispatcherUNIX::unregisterTimers: invalid argument"); | - | ||||||||||||||||||
| 369 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 370 | } else if (object->thread() != thread() || thread() != QThread::currentThread()) {
| 0 | ||||||||||||||||||
| 371 | qWarning("QEventDispatcherUNIX::unregisterTimers: timers cannot be stopped from another thread"); | - | ||||||||||||||||||
| 372 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 373 | } | - | ||||||||||||||||||
| 374 | #endif | - | ||||||||||||||||||
| 375 | - | |||||||||||||||||||
| 376 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 377 | return d->timerList.unregisterTimers(object); never executed: return d->timerList.unregisterTimers(object); | 0 | ||||||||||||||||||
| 378 | } | - | ||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | QList<QEventDispatcherUNIX::TimerInfo> | - | ||||||||||||||||||
| 381 | QEventDispatcherUNIX::registeredTimers(QObject *object) const | - | ||||||||||||||||||
| 382 | { | - | ||||||||||||||||||
| 383 | if (!object) {
| 0 | ||||||||||||||||||
| 384 | qWarning("QEventDispatcherUNIX:registeredTimers: invalid argument"); | - | ||||||||||||||||||
| 385 | return QList<TimerInfo>(); never executed: return QList<TimerInfo>(); | 0 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | Q_D(const QEventDispatcherUNIX); | - | ||||||||||||||||||
| 389 | return d->timerList.registeredTimers(object); never executed: return d->timerList.registeredTimers(object); | 0 | ||||||||||||||||||
| 390 | } | - | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | /***************************************************************************** | - | ||||||||||||||||||
| 393 | Socket notifier type | - | ||||||||||||||||||
| 394 | *****************************************************************************/ | - | ||||||||||||||||||
| 395 | QSockNotType::QSockNotType() | - | ||||||||||||||||||
| 396 | { | - | ||||||||||||||||||
| 397 | FD_ZERO(&select_fds); | - | ||||||||||||||||||
| 398 | FD_ZERO(&enabled_fds); | - | ||||||||||||||||||
| 399 | FD_ZERO(&pending_fds); | - | ||||||||||||||||||
| 400 | } never executed: end of block | 0 | ||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | QSockNotType::~QSockNotType() | - | ||||||||||||||||||
| 403 | { | - | ||||||||||||||||||
| 404 | for (int i = 0; i < list.size(); ++i)
| 0 | ||||||||||||||||||
| 405 | delete list[i]; never executed: delete list[i]; | 0 | ||||||||||||||||||
| 406 | } never executed: end of block | 0 | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | /***************************************************************************** | - | ||||||||||||||||||
| 409 | QEventDispatcher implementations for UNIX | - | ||||||||||||||||||
| 410 | *****************************************************************************/ | - | ||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | void QEventDispatcherUNIX::registerSocketNotifier(QSocketNotifier *notifier) | - | ||||||||||||||||||
| 413 | { | - | ||||||||||||||||||
| 414 | Q_ASSERT(notifier); | - | ||||||||||||||||||
| 415 | int sockfd = notifier->socket(); | - | ||||||||||||||||||
| 416 | int type = notifier->type(); | - | ||||||||||||||||||
| 417 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 418 | if (sockfd < 0
| 0 | ||||||||||||||||||
| 419 | || unsigned(sockfd) >= FD_SETSIZE) {
| 0 | ||||||||||||||||||
| 420 | qWarning("QSocketNotifier: Internal error"); | - | ||||||||||||||||||
| 421 | return; never executed: return; | 0 | ||||||||||||||||||
| 422 | } else if (notifier->thread() != thread()
| 0 | ||||||||||||||||||
| 423 | || thread() != QThread::currentThread()) {
| 0 | ||||||||||||||||||
| 424 | qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread"); | - | ||||||||||||||||||
| 425 | return; never executed: return; | 0 | ||||||||||||||||||
| 426 | } | - | ||||||||||||||||||
| 427 | #endif | - | ||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 430 | QSockNotType::List &list = d->sn_vec[type].list; | - | ||||||||||||||||||
| 431 | fd_set *fds = &d->sn_vec[type].enabled_fds; | - | ||||||||||||||||||
| 432 | QSockNot *sn; | - | ||||||||||||||||||
| 433 | - | |||||||||||||||||||
| 434 | sn = new QSockNot; | - | ||||||||||||||||||
| 435 | sn->obj = notifier; | - | ||||||||||||||||||
| 436 | sn->fd = sockfd; | - | ||||||||||||||||||
| 437 | sn->queue = &d->sn_vec[type].pending_fds; | - | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | int i; | - | ||||||||||||||||||
| 440 | for (i = 0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||
| 441 | QSockNot *p = list[i]; | - | ||||||||||||||||||
| 442 | if (p->fd < sockfd)
| 0 | ||||||||||||||||||
| 443 | break; never executed: break; | 0 | ||||||||||||||||||
| 444 | if (p->fd == sockfd) {
| 0 | ||||||||||||||||||
| 445 | static const char *t[] = { "Read", "Write", "Exception" }; | - | ||||||||||||||||||
| 446 | qWarning("QSocketNotifier: Multiple socket notifiers for " | - | ||||||||||||||||||
| 447 | "same socket %d and type %s", sockfd, t[type]); | - | ||||||||||||||||||
| 448 | } never executed: end of block | 0 | ||||||||||||||||||
| 449 | } never executed: end of block | 0 | ||||||||||||||||||
| 450 | list.insert(i, sn); | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | FD_SET(sockfd, fds); | - | ||||||||||||||||||
| 453 | d->sn_highest = qMax(d->sn_highest, sockfd); | - | ||||||||||||||||||
| 454 | } never executed: end of block | 0 | ||||||||||||||||||
| 455 | - | |||||||||||||||||||
| 456 | void QEventDispatcherUNIX::unregisterSocketNotifier(QSocketNotifier *notifier) | - | ||||||||||||||||||
| 457 | { | - | ||||||||||||||||||
| 458 | Q_ASSERT(notifier); | - | ||||||||||||||||||
| 459 | int sockfd = notifier->socket(); | - | ||||||||||||||||||
| 460 | int type = notifier->type(); | - | ||||||||||||||||||
| 461 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 462 | if (sockfd < 0
| 0 | ||||||||||||||||||
| 463 | || unsigned(sockfd) >= FD_SETSIZE) {
| 0 | ||||||||||||||||||
| 464 | qWarning("QSocketNotifier: Internal error"); | - | ||||||||||||||||||
| 465 | return; never executed: return; | 0 | ||||||||||||||||||
| 466 | } else if (notifier->thread() != thread()
| 0 | ||||||||||||||||||
| 467 | || thread() != QThread::currentThread()) {
| 0 | ||||||||||||||||||
| 468 | qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); | - | ||||||||||||||||||
| 469 | return; never executed: return; | 0 | ||||||||||||||||||
| 470 | } | - | ||||||||||||||||||
| 471 | #endif | - | ||||||||||||||||||
| 472 | - | |||||||||||||||||||
| 473 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 474 | QSockNotType::List &list = d->sn_vec[type].list; | - | ||||||||||||||||||
| 475 | fd_set *fds = &d->sn_vec[type].enabled_fds; | - | ||||||||||||||||||
| 476 | QSockNot *sn = 0; | - | ||||||||||||||||||
| 477 | int i; | - | ||||||||||||||||||
| 478 | for (i = 0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||
| 479 | sn = list[i]; | - | ||||||||||||||||||
| 480 | if(sn->obj == notifier && sn->fd == sockfd)
| 0 | ||||||||||||||||||
| 481 | break; never executed: break; | 0 | ||||||||||||||||||
| 482 | } never executed: end of block | 0 | ||||||||||||||||||
| 483 | if (i == list.size()) // not found
| 0 | ||||||||||||||||||
| 484 | return; never executed: return; | 0 | ||||||||||||||||||
| 485 | - | |||||||||||||||||||
| 486 | FD_CLR(sockfd, fds); // clear fd bit | - | ||||||||||||||||||
| 487 | FD_CLR(sockfd, sn->queue); | - | ||||||||||||||||||
| 488 | d->sn_pending_list.removeAll(sn); // remove from activation list | - | ||||||||||||||||||
| 489 | list.removeAt(i); // remove notifier found above | - | ||||||||||||||||||
| 490 | delete sn; | - | ||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | if (d->sn_highest == sockfd) { // find highest fd
| 0 | ||||||||||||||||||
| 493 | d->sn_highest = -1; | - | ||||||||||||||||||
| 494 | for (int i=0; i<3; i++) {
| 0 | ||||||||||||||||||
| 495 | if (!d->sn_vec[i].list.isEmpty())
| 0 | ||||||||||||||||||
| 496 | d->sn_highest = qMax(d->sn_highest, // list is fd-sorted never executed: d->sn_highest = qMax(d->sn_highest, d->sn_vec[i].list[0]->fd); | 0 | ||||||||||||||||||
| 497 | d->sn_vec[i].list[0]->fd); never executed: d->sn_highest = qMax(d->sn_highest, d->sn_vec[i].list[0]->fd); | 0 | ||||||||||||||||||
| 498 | } never executed: end of block | 0 | ||||||||||||||||||
| 499 | } never executed: end of block | 0 | ||||||||||||||||||
| 500 | } never executed: end of block | 0 | ||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | void QEventDispatcherUNIX::setSocketNotifierPending(QSocketNotifier *notifier) | - | ||||||||||||||||||
| 503 | { | - | ||||||||||||||||||
| 504 | Q_ASSERT(notifier); | - | ||||||||||||||||||
| 505 | int sockfd = notifier->socket(); | - | ||||||||||||||||||
| 506 | int type = notifier->type(); | - | ||||||||||||||||||
| 507 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 508 | if (sockfd < 0
| 0 | ||||||||||||||||||
| 509 | || unsigned(sockfd) >= FD_SETSIZE) {
| 0 | ||||||||||||||||||
| 510 | qWarning("QSocketNotifier: Internal error"); | - | ||||||||||||||||||
| 511 | return; never executed: return; | 0 | ||||||||||||||||||
| 512 | } | - | ||||||||||||||||||
| 513 | Q_ASSERT(notifier->thread() == thread() && thread() == QThread::currentThread()); | - | ||||||||||||||||||
| 514 | #endif | - | ||||||||||||||||||
| 515 | - | |||||||||||||||||||
| 516 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 517 | QSockNotType::List &list = d->sn_vec[type].list; | - | ||||||||||||||||||
| 518 | QSockNot *sn = 0; | - | ||||||||||||||||||
| 519 | int i; | - | ||||||||||||||||||
| 520 | for (i = 0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||
| 521 | sn = list[i]; | - | ||||||||||||||||||
| 522 | if(sn->obj == notifier && sn->fd == sockfd)
| 0 | ||||||||||||||||||
| 523 | break; never executed: break; | 0 | ||||||||||||||||||
| 524 | } never executed: end of block | 0 | ||||||||||||||||||
| 525 | if (i == list.size()) // not found
| 0 | ||||||||||||||||||
| 526 | return; never executed: return; | 0 | ||||||||||||||||||
| 527 | - | |||||||||||||||||||
| 528 | // We choose a random activation order to be more fair under high load. | - | ||||||||||||||||||
| 529 | // If a constant order is used and a peer early in the list can | - | ||||||||||||||||||
| 530 | // saturate the IO, it might grab our attention completely. | - | ||||||||||||||||||
| 531 | // Also, if we're using a straight list, the callback routines may | - | ||||||||||||||||||
| 532 | // delete other entries from the list before those other entries are | - | ||||||||||||||||||
| 533 | // processed. | - | ||||||||||||||||||
| 534 | if (! FD_ISSET(sn->fd, sn->queue)) {
| 0 | ||||||||||||||||||
| 535 | if (d->sn_pending_list.isEmpty()) {
| 0 | ||||||||||||||||||
| 536 | d->sn_pending_list.append(sn); | - | ||||||||||||||||||
| 537 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 538 | d->sn_pending_list.insert((qrand() & 0xff) % | - | ||||||||||||||||||
| 539 | (d->sn_pending_list.size()+1), sn); | - | ||||||||||||||||||
| 540 | } never executed: end of block | 0 | ||||||||||||||||||
| 541 | FD_SET(sn->fd, sn->queue); | - | ||||||||||||||||||
| 542 | } never executed: end of block | 0 | ||||||||||||||||||
| 543 | } never executed: end of block | 0 | ||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | int QEventDispatcherUNIX::activateTimers() | - | ||||||||||||||||||
| 546 | { | - | ||||||||||||||||||
| 547 | Q_ASSERT(thread() == QThread::currentThread()); | - | ||||||||||||||||||
| 548 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 549 | return d->timerList.activateTimers(); never executed: return d->timerList.activateTimers(); | 0 | ||||||||||||||||||
| 550 | } | - | ||||||||||||||||||
| 551 | - | |||||||||||||||||||
| 552 | int QEventDispatcherUNIX::activateSocketNotifiers() | - | ||||||||||||||||||
| 553 | { | - | ||||||||||||||||||
| 554 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 555 | if (d->sn_pending_list.isEmpty())
| 0 | ||||||||||||||||||
| 556 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 557 | - | |||||||||||||||||||
| 558 | // activate entries | - | ||||||||||||||||||
| 559 | int n_act = 0; | - | ||||||||||||||||||
| 560 | QEvent event(QEvent::SockAct); | - | ||||||||||||||||||
| 561 | while (!d->sn_pending_list.isEmpty()) {
| 0 | ||||||||||||||||||
| 562 | QSockNot *sn = d->sn_pending_list.takeFirst(); | - | ||||||||||||||||||
| 563 | if (FD_ISSET(sn->fd, sn->queue)) {
| 0 | ||||||||||||||||||
| 564 | FD_CLR(sn->fd, sn->queue); | - | ||||||||||||||||||
| 565 | QCoreApplication::sendEvent(sn->obj, &event); | - | ||||||||||||||||||
| 566 | ++n_act; | - | ||||||||||||||||||
| 567 | } never executed: end of block | 0 | ||||||||||||||||||
| 568 | } never executed: end of block | 0 | ||||||||||||||||||
| 569 | return n_act; never executed: return n_act; | 0 | ||||||||||||||||||
| 570 | } | - | ||||||||||||||||||
| 571 | - | |||||||||||||||||||
| 572 | bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags) | - | ||||||||||||||||||
| 573 | { | - | ||||||||||||||||||
| 574 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 575 | d->interrupt.store(0); | - | ||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | // we are awake, broadcast it | - | ||||||||||||||||||
| 578 | emit awake(); | - | ||||||||||||||||||
| 579 | QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData); | - | ||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | int nevents = 0; | - | ||||||||||||||||||
| 582 | const bool canWait = (d->threadData->canWaitLocked()
| 0 | ||||||||||||||||||
| 583 | && !d->interrupt.load()
| 0 | ||||||||||||||||||
| 584 | && (flags & QEventLoop::WaitForMoreEvents));
| 0 | ||||||||||||||||||
| 585 | - | |||||||||||||||||||
| 586 | if (canWait)
| 0 | ||||||||||||||||||
| 587 | emit aboutToBlock(); never executed: aboutToBlock(); | 0 | ||||||||||||||||||
| 588 | - | |||||||||||||||||||
| 589 | if (!d->interrupt.load()) {
| 0 | ||||||||||||||||||
| 590 | // return the maximum time we can wait for an event. | - | ||||||||||||||||||
| 591 | timespec *tm = 0; | - | ||||||||||||||||||
| 592 | timespec wait_tm = { 0l, 0l }; | - | ||||||||||||||||||
| 593 | if (!(flags & QEventLoop::X11ExcludeTimers)) {
| 0 | ||||||||||||||||||
| 594 | if (d->timerList.timerWait(wait_tm))
| 0 | ||||||||||||||||||
| 595 | tm = &wait_tm; never executed: tm = &wait_tm; | 0 | ||||||||||||||||||
| 596 | } never executed: end of block | 0 | ||||||||||||||||||
| 597 | - | |||||||||||||||||||
| 598 | if (!canWait) {
| 0 | ||||||||||||||||||
| 599 | if (!tm)
| 0 | ||||||||||||||||||
| 600 | tm = &wait_tm; never executed: tm = &wait_tm; | 0 | ||||||||||||||||||
| 601 | - | |||||||||||||||||||
| 602 | // no time to wait | - | ||||||||||||||||||
| 603 | tm->tv_sec = 0l; | - | ||||||||||||||||||
| 604 | tm->tv_nsec = 0l; | - | ||||||||||||||||||
| 605 | } never executed: end of block | 0 | ||||||||||||||||||
| 606 | - | |||||||||||||||||||
| 607 | nevents = d->doSelect(flags, tm); | - | ||||||||||||||||||
| 608 | - | |||||||||||||||||||
| 609 | // activate timers | - | ||||||||||||||||||
| 610 | if (! (flags & QEventLoop::X11ExcludeTimers)) {
| 0 | ||||||||||||||||||
| 611 | nevents += activateTimers(); | - | ||||||||||||||||||
| 612 | } never executed: end of block | 0 | ||||||||||||||||||
| 613 | } never executed: end of block | 0 | ||||||||||||||||||
| 614 | // return true if we handled events, false otherwise | - | ||||||||||||||||||
| 615 | return (nevents > 0); never executed: return (nevents > 0); | 0 | ||||||||||||||||||
| 616 | } | - | ||||||||||||||||||
| 617 | - | |||||||||||||||||||
| 618 | bool QEventDispatcherUNIX::hasPendingEvents() | - | ||||||||||||||||||
| 619 | { | - | ||||||||||||||||||
| 620 | extern uint qGlobalPostedEventsCount(); // from qapplication.cpp | - | ||||||||||||||||||
| 621 | return qGlobalPostedEventsCount(); never executed: return qGlobalPostedEventsCount(); | 0 | ||||||||||||||||||
| 622 | } | - | ||||||||||||||||||
| 623 | - | |||||||||||||||||||
| 624 | int QEventDispatcherUNIX::remainingTime(int timerId) | - | ||||||||||||||||||
| 625 | { | - | ||||||||||||||||||
| 626 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 627 | if (timerId < 1) {
| 0 | ||||||||||||||||||
| 628 | qWarning("QEventDispatcherUNIX::remainingTime: invalid argument"); | - | ||||||||||||||||||
| 629 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 630 | } | - | ||||||||||||||||||
| 631 | #endif | - | ||||||||||||||||||
| 632 | - | |||||||||||||||||||
| 633 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 634 | return d->timerList.timerRemainingTime(timerId); never executed: return d->timerList.timerRemainingTime(timerId); | 0 | ||||||||||||||||||
| 635 | } | - | ||||||||||||||||||
| 636 | - | |||||||||||||||||||
| 637 | void QEventDispatcherUNIX::wakeUp() | - | ||||||||||||||||||
| 638 | { | - | ||||||||||||||||||
| 639 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 640 | if (d->wakeUps.testAndSetAcquire(0, 1)) {
| 0 | ||||||||||||||||||
| 641 | #ifndef QT_NO_EVENTFD | - | ||||||||||||||||||
| 642 | if (d->thread_pipe[1] == -1) {
| 0 | ||||||||||||||||||
| 643 | // eventfd | - | ||||||||||||||||||
| 644 | eventfd_t value = 1; | - | ||||||||||||||||||
| 645 | int ret; | - | ||||||||||||||||||
| 646 | EINTR_LOOP(ret, eventfd_write(d->thread_pipe[0], value)); never executed: end of block
| 0 | ||||||||||||||||||
| 647 | return; never executed: return; | 0 | ||||||||||||||||||
| 648 | } | - | ||||||||||||||||||
| 649 | #endif | - | ||||||||||||||||||
| 650 | char c = 0; | - | ||||||||||||||||||
| 651 | qt_safe_write( d->thread_pipe[1], &c, 1 ); | - | ||||||||||||||||||
| 652 | } never executed: end of block | 0 | ||||||||||||||||||
| 653 | } never executed: end of block | 0 | ||||||||||||||||||
| 654 | - | |||||||||||||||||||
| 655 | void QEventDispatcherUNIX::interrupt() | - | ||||||||||||||||||
| 656 | { | - | ||||||||||||||||||
| 657 | Q_D(QEventDispatcherUNIX); | - | ||||||||||||||||||
| 658 | d->interrupt.store(1); | - | ||||||||||||||||||
| 659 | wakeUp(); | - | ||||||||||||||||||
| 660 | } never executed: end of block | 0 | ||||||||||||||||||
| 661 | - | |||||||||||||||||||
| 662 | void QEventDispatcherUNIX::flush() | - | ||||||||||||||||||
| 663 | { } | - | ||||||||||||||||||
| 664 | - | |||||||||||||||||||
| 665 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |