kernel/qeventdispatcher_unix.cpp

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

Generated by Squish Coco Non-Commercial