kernel/qeventdispatcher_glib.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 "qeventdispatcher_glib_p.h" -
43#include "qeventdispatcher_unix_p.h" -
44 -
45#include <private/qthread_p.h> -
46 -
47#include "qcoreapplication.h" -
48#include "qsocketnotifier.h" -
49 -
50#include <QtCore/qhash.h> -
51#include <QtCore/qlist.h> -
52#include <QtCore/qpair.h> -
53 -
54#include <glib.h> -
55 -
56QT_BEGIN_NAMESPACE -
57 -
58struct GPollFDWithQSocketNotifier -
59{ -
60 GPollFD pollfd; -
61 QSocketNotifier *socketNotifier; -
62}; -
63 -
64struct GSocketNotifierSource -
65{ -
66 GSource source; -
67 QList<GPollFDWithQSocketNotifier *> pollfds; -
68}; -
69 -
70static gboolean socketNotifierSourcePrepare(GSource *, gint *timeout) -
71{ -
72 if (timeout)
partially evaluated: timeout
TRUEFALSE
yes
Evaluation Count:626990
no
Evaluation Count:0
0-626990
73 *timeout = -1;
executed: *timeout = -1;
Execution Count:626981
626981
74 return false;
executed: return false;
Execution Count:627004
627004
75} -
76 -
77static gboolean socketNotifierSourceCheck(GSource *source) -
78{ -
79 GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);
executed (the execution status of this line is deduced): GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);
-
80 -
81 bool pending = false;
executed (the execution status of this line is deduced): bool pending = false;
-
82 for (int i = 0; !pending && i < src->pollfds.count(); ++i) {
evaluated: !pending
TRUEFALSE
yes
Evaluation Count:1254963
yes
Evaluation Count:19255
evaluated: i < src->pollfds.count()
TRUEFALSE
yes
Evaluation Count:647242
yes
Evaluation Count:607777
19255-1254963
83 GPollFDWithQSocketNotifier *p = src->pollfds.at(i);
executed (the execution status of this line is deduced): GPollFDWithQSocketNotifier *p = src->pollfds.at(i);
-
84 -
85 if (p->pollfd.revents & G_IO_NVAL) {
partially evaluated: p->pollfd.revents & G_IO_NVAL
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:647241
0-647241
86 // disable the invalid socket notifier -
87 static const char *t[] = { "Read", "Write", "Exception" }; -
88 qWarning("QSocketNotifier: Invalid socket %d and type '%s', disabling...",
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qeventdispatcher_glib.cpp", 88, __PRETTY_FUNCTION__).warning("QSocketNotifier: Invalid socket %d and type '%s', disabling...",
-
89 p->pollfd.fd, t[int(p->socketNotifier->type())]);
never executed (the execution status of this line is deduced): p->pollfd.fd, t[int(p->socketNotifier->type())]);
-
90 // ### note, modifies src->pollfds! -
91 p->socketNotifier->setEnabled(false);
never executed (the execution status of this line is deduced): p->socketNotifier->setEnabled(false);
-
92 }
never executed: }
0
93 -
94 pending = ((p->pollfd.revents & p->pollfd.events) != 0);
executed (the execution status of this line is deduced): pending = ((p->pollfd.revents & p->pollfd.events) != 0);
-
95 }
executed: }
Execution Count:647241
647241
96 -
97 return pending;
executed: return pending;
Execution Count:627035
627035
98} -
99 -
100static gboolean socketNotifierSourceDispatch(GSource *source, GSourceFunc, gpointer) -
101{ -
102 QEvent event(QEvent::SockAct);
executed (the execution status of this line is deduced): QEvent event(QEvent::SockAct);
-
103 -
104 GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);
executed (the execution status of this line is deduced): GSocketNotifierSource *src = reinterpret_cast<GSocketNotifierSource *>(source);
-
105 for (int i = 0; i < src->pollfds.count(); ++i) {
evaluated: i < src->pollfds.count()
TRUEFALSE
yes
Evaluation Count:49293
yes
Evaluation Count:19253
19253-49293
106 GPollFDWithQSocketNotifier *p = src->pollfds.at(i);
executed (the execution status of this line is deduced): GPollFDWithQSocketNotifier *p = src->pollfds.at(i);
-
107 -
108 if ((p->pollfd.revents & p->pollfd.events) != 0)
evaluated: (p->pollfd.revents & p->pollfd.events) != 0
TRUEFALSE
yes
Evaluation Count:19641
yes
Evaluation Count:29652
19641-29652
109 QCoreApplication::sendEvent(p->socketNotifier, &event);
executed: QCoreApplication::sendEvent(p->socketNotifier, &event);
Execution Count:19641
19641
110 }
executed: }
Execution Count:49282
49282
111 -
112 return true; // ??? don't remove, right?
executed: return true;
Execution Count:19253
19253
113} -
114 -
115static GSourceFuncs socketNotifierSourceFuncs = { -
116 socketNotifierSourcePrepare, -
117 socketNotifierSourceCheck, -
118 socketNotifierSourceDispatch, -
119 NULL, -
120 NULL, -
121 NULL -
122}; -
123 -
124struct GTimerSource -
125{ -
126 GSource source; -
127 QTimerInfoList timerList; -
128 QEventLoop::ProcessEventsFlags processEventsFlags; -
129 bool runWithIdlePriority; -
130}; -
131 -
132static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout) -
133{ -
134 timeval tv = { 0l, 0l };
executed (the execution status of this line is deduced): timeval tv = { 0l, 0l };
-
135 if (!(src->processEventsFlags & QEventLoop::X11ExcludeTimers) && src->timerList.timerWait(tv))
evaluated: !(src->processEventsFlags & QEventLoop::X11ExcludeTimers)
TRUEFALSE
yes
Evaluation Count:626543
yes
Evaluation Count:1
evaluated: src->timerList.timerWait(tv)
TRUEFALSE
yes
Evaluation Count:301591
yes
Evaluation Count:324952
1-626543
136 *timeout = (tv.tv_sec * 1000) + ((tv.tv_usec + 999) / 1000);
executed: *timeout = (tv.tv_sec * 1000) + ((tv.tv_usec + 999) / 1000);
Execution Count:301591
301591
137 else -
138 *timeout = -1;
executed: *timeout = -1;
Execution Count:324961
324961
139 -
140 return (*timeout == 0);
executed: return (*timeout == 0);
Execution Count:626572
626572
141} -
142 -
143static gboolean timerSourceCheckHelper(GTimerSource *src) -
144{ -
145 if (src->timerList.isEmpty()
evaluated: src->timerList.isEmpty()
TRUEFALSE
yes
Evaluation Count:324960
yes
Evaluation Count:262290
262290-324960
146 || (src->processEventsFlags & QEventLoop::X11ExcludeTimers))
evaluated: (src->processEventsFlags & QEventLoop::X11ExcludeTimers)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:262289
1-262289
147 return false;
executed: return false;
Execution Count:325004
325004
148 -
149 if (src->timerList.updateCurrentTime() < src->timerList.first()->timeout)
evaluated: src->timerList.updateCurrentTime() < src->timerList.first()->timeout
TRUEFALSE
yes
Evaluation Count:259722
yes
Evaluation Count:2567
2567-259722
150 return false;
executed: return false;
Execution Count:259722
259722
151 -
152 return true;
executed: return true;
Execution Count:2567
2567
153} -
154 -
155static gboolean timerSourcePrepare(GSource *source, gint *timeout) -
156{ -
157 gint dummy;
executed (the execution status of this line is deduced): gint dummy;
-
158 if (!timeout)
partially evaluated: !timeout
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:627012
0-627012
159 timeout = &dummy;
never executed: timeout = &dummy;
0
160 -
161 GTimerSource *src = reinterpret_cast<GTimerSource *>(source);
executed (the execution status of this line is deduced): GTimerSource *src = reinterpret_cast<GTimerSource *>(source);
-
162 if (src->runWithIdlePriority) {
evaluated: src->runWithIdlePriority
TRUEFALSE
yes
Evaluation Count:2730
yes
Evaluation Count:624280
2730-624280
163 if (timeout)
partially evaluated: timeout
TRUEFALSE
yes
Evaluation Count:2730
no
Evaluation Count:0
0-2730
164 *timeout = -1;
executed: *timeout = -1;
Execution Count:2730
2730
165 return false;
executed: return false;
Execution Count:2730
2730
166 } -
167 -
168 return timerSourcePrepareHelper(src, timeout);
executed: return timerSourcePrepareHelper(src, timeout);
Execution Count:624283
624283
169} -
170 -
171static gboolean timerSourceCheck(GSource *source) -
172{ -
173 GTimerSource *src = reinterpret_cast<GTimerSource *>(source);
executed (the execution status of this line is deduced): GTimerSource *src = reinterpret_cast<GTimerSource *>(source);
-
174 if (src->runWithIdlePriority)
evaluated: src->runWithIdlePriority
TRUEFALSE
yes
Evaluation Count:2730
yes
Evaluation Count:585873
2730-585873
175 return false;
executed: return false;
Execution Count:2730
2730
176 return timerSourceCheckHelper(src);
executed: return timerSourceCheckHelper(src);
Execution Count:585884
585884
177} -
178 -
179static gboolean timerSourceDispatch(GSource *source, GSourceFunc, gpointer) -
180{ -
181 GTimerSource *timerSource = reinterpret_cast<GTimerSource *>(source);
executed (the execution status of this line is deduced): GTimerSource *timerSource = reinterpret_cast<GTimerSource *>(source);
-
182 if (timerSource->processEventsFlags & QEventLoop::X11ExcludeTimers)
partially evaluated: timerSource->processEventsFlags & QEventLoop::X11ExcludeTimers
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:40996
0-40996
183 return true;
never executed: return true;
0
184 timerSource->runWithIdlePriority = true;
executed (the execution status of this line is deduced): timerSource->runWithIdlePriority = true;
-
185 (void) timerSource->timerList.activateTimers();
executed (the execution status of this line is deduced): (void) timerSource->timerList.activateTimers();
-
186 return true; // ??? don't remove, right again?
executed: return true;
Execution Count:40996
40996
187} -
188 -
189static GSourceFuncs timerSourceFuncs = { -
190 timerSourcePrepare, -
191 timerSourceCheck, -
192 timerSourceDispatch, -
193 NULL, -
194 NULL, -
195 NULL -
196}; -
197 -
198struct GIdleTimerSource -
199{ -
200 GSource source; -
201 GTimerSource *timerSource; -
202}; -
203 -
204static gboolean idleTimerSourcePrepare(GSource *source, gint *timeout) -
205{ -
206 GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source);
executed (the execution status of this line is deduced): GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source);
-
207 GTimerSource *timerSource = idleTimerSource->timerSource;
executed (the execution status of this line is deduced): GTimerSource *timerSource = idleTimerSource->timerSource;
-
208 if (!timerSource->runWithIdlePriority) {
evaluated: !timerSource->runWithIdlePriority
TRUEFALSE
yes
Evaluation Count:308516
yes
Evaluation Count:2303
2303-308516
209 // Yield to the normal priority timer source -
210 if (timeout)
partially evaluated: timeout
TRUEFALSE
yes
Evaluation Count:308520
no
Evaluation Count:0
0-308520
211 *timeout = -1;
executed: *timeout = -1;
Execution Count:308516
308516
212 return false;
executed: return false;
Execution Count:308518
308518
213 } -
214 -
215 return timerSourcePrepareHelper(timerSource, timeout);
executed: return timerSourcePrepareHelper(timerSource, timeout);
Execution Count:2303
2303
216} -
217 -
218static gboolean idleTimerSourceCheck(GSource *source) -
219{ -
220 GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source);
executed (the execution status of this line is deduced): GIdleTimerSource *idleTimerSource = reinterpret_cast<GIdleTimerSource *>(source);
-
221 GTimerSource *timerSource = idleTimerSource->timerSource;
executed (the execution status of this line is deduced): GTimerSource *timerSource = idleTimerSource->timerSource;
-
222 if (!timerSource->runWithIdlePriority) {
evaluated: !timerSource->runWithIdlePriority
TRUEFALSE
yes
Evaluation Count:275439
yes
Evaluation Count:1404
1404-275439
223 // Yield to the normal priority timer source -
224 return false;
executed: return false;
Execution Count:275445
275445
225 } -
226 return timerSourceCheckHelper(timerSource);
executed: return timerSourceCheckHelper(timerSource);
Execution Count:1404
1404
227} -
228 -
229static gboolean idleTimerSourceDispatch(GSource *source, GSourceFunc, gpointer) -
230{ -
231 GTimerSource *timerSource = reinterpret_cast<GIdleTimerSource *>(source)->timerSource;
executed (the execution status of this line is deduced): GTimerSource *timerSource = reinterpret_cast<GIdleTimerSource *>(source)->timerSource;
-
232 (void) timerSourceDispatch(&timerSource->source, 0, 0);
executed (the execution status of this line is deduced): (void) timerSourceDispatch(&timerSource->source, 0, 0);
-
233 return true;
executed: return true;
Execution Count:1429
1429
234} -
235 -
236static GSourceFuncs idleTimerSourceFuncs = { -
237 idleTimerSourcePrepare, -
238 idleTimerSourceCheck, -
239 idleTimerSourceDispatch, -
240 NULL, -
241 NULL, -
242 NULL -
243}; -
244 -
245struct GPostEventSource -
246{ -
247 GSource source; -
248 QAtomicInt serialNumber; -
249 int lastSerialNumber; -
250 QEventDispatcherGlibPrivate *d; -
251}; -
252 -
253static gboolean postEventSourcePrepare(GSource *s, gint *timeout) -
254{ -
255 QThreadData *data = QThreadData::current();
executed (the execution status of this line is deduced): QThreadData *data = QThreadData::current();
-
256 if (!data)
partially evaluated: !data
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:940400
0-940400
257 return false;
never executed: return false;
0
258 -
259 gint dummy;
executed (the execution status of this line is deduced): gint dummy;
-
260 if (!timeout)
evaluated: !timeout
TRUEFALSE
yes
Evaluation Count:313449
yes
Evaluation Count:626990
313449-626990
261 timeout = &dummy;
executed: timeout = &dummy;
Execution Count:313452
313452
262 *timeout = data->canWait ? -1 : 0;
evaluated: data->canWait
TRUEFALSE
yes
Evaluation Count:612288
yes
Evaluation Count:328152
328152-612288
263 -
264 GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
executed (the execution status of this line is deduced): GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
-
265 return (!data->canWait
executed: return (!data->canWait || (source->serialNumber.load() != source->lastSerialNumber));
Execution Count:940418
940418
266 || (source->serialNumber.load() != source->lastSerialNumber));
executed: return (!data->canWait || (source->serialNumber.load() != source->lastSerialNumber));
Execution Count:940418
940418
267} -
268 -
269static gboolean postEventSourceCheck(GSource *source) -
270{ -
271 return postEventSourcePrepare(source, 0);
executed: return postEventSourcePrepare(source, 0);
Execution Count:313433
313433
272} -
273 -
274static gboolean postEventSourceDispatch(GSource *s, GSourceFunc, gpointer) -
275{ -
276 GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
executed (the execution status of this line is deduced): GPostEventSource *source = reinterpret_cast<GPostEventSource *>(s);
-
277 source->lastSerialNumber = source->serialNumber.load();
executed (the execution status of this line is deduced): source->lastSerialNumber = source->serialNumber.load();
-
278 QCoreApplication::sendPostedEvents();
executed (the execution status of this line is deduced): QCoreApplication::sendPostedEvents();
-
279 source->d->runTimersOnceWithNormalPriority();
executed (the execution status of this line is deduced): source->d->runTimersOnceWithNormalPriority();
-
280 return true; // i dunno, george...
executed: return true;
Execution Count:332663
332663
281} -
282 -
283static GSourceFuncs postEventSourceFuncs = { -
284 postEventSourcePrepare, -
285 postEventSourceCheck, -
286 postEventSourceDispatch, -
287 NULL, -
288 NULL, -
289 NULL -
290}; -
291 -
292 -
293QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) -
294 : mainContext(context) -
295{ -
296 if (qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")) {
partially evaluated: qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")
TRUEFALSE
yes
Evaluation Count:1717535
no
Evaluation Count:0
0-1717535
297 static QBasicMutex mutex; -
298 QMutexLocker locker(&mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&mutex);
-
299 if (!g_thread_supported())
evaluated: !(g_threads_got_initialized)
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1717533
8-1717533
300 g_thread_init(NULL);
executed: g_thread_init(__null);
Execution Count:8
8
301 }
executed: }
Execution Count:1717541
1717541
302 -
303 if (mainContext) {
partially evaluated: mainContext
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1717541
0-1717541
304 g_main_context_ref(mainContext);
never executed (the execution status of this line is deduced): g_main_context_ref(mainContext);
-
305 } else {
never executed: }
0
306 QCoreApplication *app = QCoreApplication::instance();
executed (the execution status of this line is deduced): QCoreApplication *app = QCoreApplication::instance();
-
307 if (app && QThread::currentThread() == app->thread()) {
evaluated: app
TRUEFALSE
yes
Evaluation Count:1717509
yes
Evaluation Count:32
evaluated: QThread::currentThread() == app->thread()
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:1717363
32-1717509
308 mainContext = g_main_context_default();
executed (the execution status of this line is deduced): mainContext = g_main_context_default();
-
309 g_main_context_ref(mainContext);
executed (the execution status of this line is deduced): g_main_context_ref(mainContext);
-
310 } else {
executed: }
Execution Count:144
144
311 mainContext = g_main_context_new();
executed (the execution status of this line is deduced): mainContext = g_main_context_new();
-
312 }
executed: }
Execution Count:1717397
1717397
313 } -
314 -
315#if GLIB_CHECK_VERSION (2, 22, 0) -
316 g_main_context_push_thread_default (mainContext);
executed (the execution status of this line is deduced): g_main_context_push_thread_default (mainContext);
-
317#endif -
318 -
319 // setup post event source -
320 postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs,
executed (the execution status of this line is deduced): postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs,
-
321 sizeof(GPostEventSource)));
executed (the execution status of this line is deduced): sizeof(GPostEventSource)));
-
322 postEventSource->serialNumber.store(1);
executed (the execution status of this line is deduced): postEventSource->serialNumber.store(1);
-
323 postEventSource->d = this;
executed (the execution status of this line is deduced): postEventSource->d = this;
-
324 g_source_set_can_recurse(&postEventSource->source, true);
executed (the execution status of this line is deduced): g_source_set_can_recurse(&postEventSource->source, true);
-
325 g_source_attach(&postEventSource->source, mainContext);
executed (the execution status of this line is deduced): g_source_attach(&postEventSource->source, mainContext);
-
326 -
327 // setup socketNotifierSource -
328 socketNotifierSource =
executed (the execution status of this line is deduced): socketNotifierSource =
-
329 reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs,
executed (the execution status of this line is deduced): reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs,
-
330 sizeof(GSocketNotifierSource)));
executed (the execution status of this line is deduced): sizeof(GSocketNotifierSource)));
-
331 (void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>();
executed (the execution status of this line is deduced): (void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>();
-
332 g_source_set_can_recurse(&socketNotifierSource->source, true);
executed (the execution status of this line is deduced): g_source_set_can_recurse(&socketNotifierSource->source, true);
-
333 g_source_attach(&socketNotifierSource->source, mainContext);
executed (the execution status of this line is deduced): g_source_attach(&socketNotifierSource->source, mainContext);
-
334 -
335 // setup normal and idle timer sources -
336 timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs,
executed (the execution status of this line is deduced): timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs,
-
337 sizeof(GTimerSource)));
executed (the execution status of this line is deduced): sizeof(GTimerSource)));
-
338 (void) new (&timerSource->timerList) QTimerInfoList();
executed (the execution status of this line is deduced): (void) new (&timerSource->timerList) QTimerInfoList();
-
339 timerSource->processEventsFlags = QEventLoop::AllEvents;
executed (the execution status of this line is deduced): timerSource->processEventsFlags = QEventLoop::AllEvents;
-
340 timerSource->runWithIdlePriority = false;
executed (the execution status of this line is deduced): timerSource->runWithIdlePriority = false;
-
341 g_source_set_can_recurse(&timerSource->source, true);
executed (the execution status of this line is deduced): g_source_set_can_recurse(&timerSource->source, true);
-
342 g_source_attach(&timerSource->source, mainContext);
executed (the execution status of this line is deduced): g_source_attach(&timerSource->source, mainContext);
-
343 -
344 idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs,
executed (the execution status of this line is deduced): idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs,
-
345 sizeof(GIdleTimerSource)));
executed (the execution status of this line is deduced): sizeof(GIdleTimerSource)));
-
346 idleTimerSource->timerSource = timerSource;
executed (the execution status of this line is deduced): idleTimerSource->timerSource = timerSource;
-
347 g_source_set_can_recurse(&idleTimerSource->source, true);
executed (the execution status of this line is deduced): g_source_set_can_recurse(&idleTimerSource->source, true);
-
348 g_source_set_priority(&idleTimerSource->source, G_PRIORITY_DEFAULT_IDLE);
executed (the execution status of this line is deduced): g_source_set_priority(&idleTimerSource->source, 200);
-
349 g_source_attach(&idleTimerSource->source, mainContext);
executed (the execution status of this line is deduced): g_source_attach(&idleTimerSource->source, mainContext);
-
350}
executed: }
Execution Count:1717535
1717535
351 -
352void QEventDispatcherGlibPrivate::runTimersOnceWithNormalPriority() -
353{ -
354 timerSource->runWithIdlePriority = false;
executed (the execution status of this line is deduced): timerSource->runWithIdlePriority = false;
-
355}
executed: }
Execution Count:332662
332662
356 -
357QEventDispatcherGlib::QEventDispatcherGlib(QObject *parent) -
358 : QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate), parent) -
359{ -
360}
executed: }
Execution Count:1717406
1717406
361 -
362QEventDispatcherGlib::QEventDispatcherGlib(GMainContext *mainContext, QObject *parent) -
363 : QAbstractEventDispatcher(*(new QEventDispatcherGlibPrivate(mainContext)), parent) -
364{ }
never executed: }
0
365 -
366QEventDispatcherGlib::~QEventDispatcherGlib() -
367{ -
368 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
369 -
370 // destroy all timer sources -
371 qDeleteAll(d->timerSource->timerList);
executed (the execution status of this line is deduced): qDeleteAll(d->timerSource->timerList);
-
372 d->timerSource->timerList.~QTimerInfoList();
executed (the execution status of this line is deduced): d->timerSource->timerList.~QTimerInfoList();
-
373 g_source_destroy(&d->timerSource->source);
executed (the execution status of this line is deduced): g_source_destroy(&d->timerSource->source);
-
374 g_source_unref(&d->timerSource->source);
executed (the execution status of this line is deduced): g_source_unref(&d->timerSource->source);
-
375 d->timerSource = 0;
executed (the execution status of this line is deduced): d->timerSource = 0;
-
376 g_source_destroy(&d->idleTimerSource->source);
executed (the execution status of this line is deduced): g_source_destroy(&d->idleTimerSource->source);
-
377 g_source_unref(&d->idleTimerSource->source);
executed (the execution status of this line is deduced): g_source_unref(&d->idleTimerSource->source);
-
378 d->idleTimerSource = 0;
executed (the execution status of this line is deduced): d->idleTimerSource = 0;
-
379 -
380 // destroy socket notifier source -
381 for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) {
evaluated: i < d->socketNotifierSource->pollfds.count()
TRUEFALSE
yes
Evaluation Count:506
yes
Evaluation Count:1717836
506-1717836
382 GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds[i];
executed (the execution status of this line is deduced): GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds[i];
-
383 g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd);
executed (the execution status of this line is deduced): g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd);
-
384 delete p;
executed (the execution status of this line is deduced): delete p;
-
385 }
executed: }
Execution Count:506
506
386 d->socketNotifierSource->pollfds.~QList<GPollFDWithQSocketNotifier *>();
executed (the execution status of this line is deduced): d->socketNotifierSource->pollfds.~QList<GPollFDWithQSocketNotifier *>();
-
387 g_source_destroy(&d->socketNotifierSource->source);
executed (the execution status of this line is deduced): g_source_destroy(&d->socketNotifierSource->source);
-
388 g_source_unref(&d->socketNotifierSource->source);
executed (the execution status of this line is deduced): g_source_unref(&d->socketNotifierSource->source);
-
389 d->socketNotifierSource = 0;
executed (the execution status of this line is deduced): d->socketNotifierSource = 0;
-
390 -
391 // destroy post event source -
392 g_source_destroy(&d->postEventSource->source);
executed (the execution status of this line is deduced): g_source_destroy(&d->postEventSource->source);
-
393 g_source_unref(&d->postEventSource->source);
executed (the execution status of this line is deduced): g_source_unref(&d->postEventSource->source);
-
394 d->postEventSource = 0;
executed (the execution status of this line is deduced): d->postEventSource = 0;
-
395 -
396 Q_ASSERT(d->mainContext != 0);
executed (the execution status of this line is deduced): qt_noop();
-
397#if GLIB_CHECK_VERSION (2, 22, 0) -
398 g_main_context_pop_thread_default (d->mainContext);
executed (the execution status of this line is deduced): g_main_context_pop_thread_default (d->mainContext);
-
399#endif -
400 g_main_context_unref(d->mainContext);
executed (the execution status of this line is deduced): g_main_context_unref(d->mainContext);
-
401 d->mainContext = 0;
executed (the execution status of this line is deduced): d->mainContext = 0;
-
402}
executed: }
Execution Count:1717848
1717848
403 -
404bool QEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags) -
405{ -
406 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
407 -
408 const bool canWait = (flags & QEventLoop::WaitForMoreEvents);
executed (the execution status of this line is deduced): const bool canWait = (flags & QEventLoop::WaitForMoreEvents);
-
409 if (canWait)
evaluated: canWait
TRUEFALSE
yes
Evaluation Count:98942
yes
Evaluation Count:528058
98942-528058
410 emit aboutToBlock();
executed: aboutToBlock();
Execution Count:98944
98944
411 else -
412 emit awake();
executed: awake();
Execution Count:528053
528053
413 -
414 // tell postEventSourcePrepare() and timerSource about any new flags -
415 QEventLoop::ProcessEventsFlags savedFlags = d->timerSource->processEventsFlags;
executed (the execution status of this line is deduced): QEventLoop::ProcessEventsFlags savedFlags = d->timerSource->processEventsFlags;
-
416 d->timerSource->processEventsFlags = flags;
executed (the execution status of this line is deduced): d->timerSource->processEventsFlags = flags;
-
417 -
418 if (!(flags & QEventLoop::EventLoopExec)) {
evaluated: !(flags & QEventLoop::EventLoopExec)
TRUEFALSE
yes
Evaluation Count:566988
yes
Evaluation Count:60059
60059-566988
419 // force timers to be sent at normal priority -
420 d->timerSource->runWithIdlePriority = false;
executed (the execution status of this line is deduced): d->timerSource->runWithIdlePriority = false;
-
421 }
executed: }
Execution Count:566989
566989
422 -
423 bool result = g_main_context_iteration(d->mainContext, canWait);
executed (the execution status of this line is deduced): bool result = g_main_context_iteration(d->mainContext, canWait);
-
424 while (!result && canWait)
evaluated: !result
TRUEFALSE
yes
Evaluation Count:275449
yes
Evaluation Count:351585
evaluated: canWait
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:275457
2-351585
425 result = g_main_context_iteration(d->mainContext, canWait);
executed: result = g_main_context_iteration(d->mainContext, canWait);
Execution Count:2
2
426 -
427 d->timerSource->processEventsFlags = savedFlags;
executed (the execution status of this line is deduced): d->timerSource->processEventsFlags = savedFlags;
-
428 -
429 if (canWait)
evaluated: canWait
TRUEFALSE
yes
Evaluation Count:98938
yes
Evaluation Count:528082
98938-528082
430 emit awake();
executed: awake();
Execution Count:98942
98942
431 -
432 return result;
executed: return result;
Execution Count:626961
626961
433} -
434 -
435bool QEventDispatcherGlib::hasPendingEvents() -
436{ -
437 Q_D(QEventDispatcherGlib);
never executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
438 return g_main_context_pending(d->mainContext);
never executed: return g_main_context_pending(d->mainContext);
0
439} -
440 -
441void QEventDispatcherGlib::registerSocketNotifier(QSocketNotifier *notifier) -
442{ -
443 Q_ASSERT(notifier);
executed (the execution status of this line is deduced): qt_noop();
-
444 int sockfd = notifier->socket();
executed (the execution status of this line is deduced): int sockfd = notifier->socket();
-
445 int type = notifier->type();
executed (the execution status of this line is deduced): int type = notifier->type();
-
446#ifndef QT_NO_DEBUG -
447 if (sockfd < 0) { -
448 qWarning("QSocketNotifier: Internal error"); -
449 return; -
450 } else if (notifier->thread() != thread() -
451 || thread() != QThread::currentThread()) { -
452 qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread"); -
453 return; -
454 } -
455#endif -
456 -
457 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
458 -
459 -
460 GPollFDWithQSocketNotifier *p = new GPollFDWithQSocketNotifier;
executed (the execution status of this line is deduced): GPollFDWithQSocketNotifier *p = new GPollFDWithQSocketNotifier;
-
461 p->pollfd.fd = sockfd;
executed (the execution status of this line is deduced): p->pollfd.fd = sockfd;
-
462 switch (type) { -
463 case QSocketNotifier::Read: -
464 p->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
executed (the execution status of this line is deduced): p->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
-
465 break;
executed: break;
Execution Count:19789
19789
466 case QSocketNotifier::Write: -
467 p->pollfd.events = G_IO_OUT | G_IO_ERR;
executed (the execution status of this line is deduced): p->pollfd.events = G_IO_OUT | G_IO_ERR;
-
468 break;
executed: break;
Execution Count:23912
23912
469 case QSocketNotifier::Exception: -
470 p->pollfd.events = G_IO_PRI | G_IO_ERR;
never executed (the execution status of this line is deduced): p->pollfd.events = G_IO_PRI | G_IO_ERR;
-
471 break;
never executed: break;
0
472 } -
473 p->socketNotifier = notifier;
executed (the execution status of this line is deduced): p->socketNotifier = notifier;
-
474 -
475 d->socketNotifierSource->pollfds.append(p);
executed (the execution status of this line is deduced): d->socketNotifierSource->pollfds.append(p);
-
476 -
477 g_source_add_poll(&d->socketNotifierSource->source, &p->pollfd);
executed (the execution status of this line is deduced): g_source_add_poll(&d->socketNotifierSource->source, &p->pollfd);
-
478}
executed: }
Execution Count:43701
43701
479 -
480void QEventDispatcherGlib::unregisterSocketNotifier(QSocketNotifier *notifier) -
481{ -
482 Q_ASSERT(notifier);
executed (the execution status of this line is deduced): qt_noop();
-
483#ifndef QT_NO_DEBUG -
484 int sockfd = notifier->socket(); -
485 if (sockfd < 0) { -
486 qWarning("QSocketNotifier: Internal error"); -
487 return; -
488 } else if (notifier->thread() != thread() -
489 || thread() != QThread::currentThread()) { -
490 qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); -
491 return; -
492 } -
493#endif -
494 -
495 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
496 -
497 for (int i = 0; i < d->socketNotifierSource->pollfds.count(); ++i) {
partially evaluated: i < d->socketNotifierSource->pollfds.count()
TRUEFALSE
yes
Evaluation Count:101624
no
Evaluation Count:0
0-101624
498 GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds.at(i);
executed (the execution status of this line is deduced): GPollFDWithQSocketNotifier *p = d->socketNotifierSource->pollfds.at(i);
-
499 if (p->socketNotifier == notifier) {
evaluated: p->socketNotifier == notifier
TRUEFALSE
yes
Evaluation Count:43564
yes
Evaluation Count:58062
43564-58062
500 // found it -
501 g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd);
executed (the execution status of this line is deduced): g_source_remove_poll(&d->socketNotifierSource->source, &p->pollfd);
-
502 -
503 d->socketNotifierSource->pollfds.removeAt(i);
executed (the execution status of this line is deduced): d->socketNotifierSource->pollfds.removeAt(i);
-
504 delete p;
executed (the execution status of this line is deduced): delete p;
-
505 -
506 return;
executed: return;
Execution Count:43564
43564
507 } -
508 }
executed: }
Execution Count:58063
58063
509}
never executed: }
0
510 -
511void QEventDispatcherGlib::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object) -
512{ -
513#ifndef QT_NO_DEBUG -
514 if (timerId < 1 || interval < 0 || !object) { -
515 qWarning("QEventDispatcherGlib::registerTimer: invalid arguments"); -
516 return; -
517 } else if (object->thread() != thread() || thread() != QThread::currentThread()) { -
518 qWarning("QObject::startTimer: timers cannot be started from another thread"); -
519 return; -
520 } -
521#endif -
522 -
523 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
524 d->timerSource->timerList.registerTimer(timerId, interval, timerType, object);
executed (the execution status of this line is deduced): d->timerSource->timerList.registerTimer(timerId, interval, timerType, object);
-
525}
executed: }
Execution Count:132417
132417
526 -
527bool QEventDispatcherGlib::unregisterTimer(int timerId) -
528{ -
529#ifndef QT_NO_DEBUG -
530 if (timerId < 1) { -
531 qWarning("QEventDispatcherGlib::unregisterTimer: invalid argument"); -
532 return false; -
533 } else if (thread() != QThread::currentThread()) { -
534 qWarning("QObject::killTimer: timers cannot be stopped from another thread"); -
535 return false; -
536 } -
537#endif -
538 -
539 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
540 return d->timerSource->timerList.unregisterTimer(timerId);
executed: return d->timerSource->timerList.unregisterTimer(timerId);
Execution Count:129527
129527
541} -
542 -
543bool QEventDispatcherGlib::unregisterTimers(QObject *object) -
544{ -
545#ifndef QT_NO_DEBUG -
546 if (!object) { -
547 qWarning("QEventDispatcherGlib::unregisterTimers: invalid argument"); -
548 return false; -
549 } else if (object->thread() != thread() || thread() != QThread::currentThread()) { -
550 qWarning("QObject::killTimers: timers cannot be stopped from another thread"); -
551 return false; -
552 } -
553#endif -
554 -
555 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
556 return d->timerSource->timerList.unregisterTimers(object);
executed: return d->timerSource->timerList.unregisterTimers(object);
Execution Count:1181
1181
557} -
558 -
559QList<QEventDispatcherGlib::TimerInfo> QEventDispatcherGlib::registeredTimers(QObject *object) const -
560{ -
561 if (!object) {
partially evaluated: !object
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:23317
0-23317
562 qWarning("QEventDispatcherUNIX:registeredTimers: invalid argument");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qeventdispatcher_glib.cpp", 562, __PRETTY_FUNCTION__).warning("QEventDispatcherUNIX:registeredTimers: invalid argument");
-
563 return QList<TimerInfo>();
never executed: return QList<TimerInfo>();
0
564 } -
565 -
566 Q_D(const QEventDispatcherGlib);
executed (the execution status of this line is deduced): const QEventDispatcherGlibPrivate * const d = d_func();
-
567 return d->timerSource->timerList.registeredTimers(object);
executed: return d->timerSource->timerList.registeredTimers(object);
Execution Count:23315
23315
568} -
569 -
570int QEventDispatcherGlib::remainingTime(int timerId) -
571{ -
572#ifndef QT_NO_DEBUG -
573 if (timerId < 1) { -
574 qWarning("QEventDispatcherGlib::remainingTimeTime: invalid argument"); -
575 return -1; -
576 } -
577#endif -
578 -
579 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
580 return d->timerSource->timerList.timerRemainingTime(timerId);
executed: return d->timerSource->timerList.timerRemainingTime(timerId);
Execution Count:1
1
581} -
582 -
583void QEventDispatcherGlib::interrupt() -
584{ -
585 wakeUp();
executed (the execution status of this line is deduced): wakeUp();
-
586}
executed: }
Execution Count:2707
2707
587 -
588void QEventDispatcherGlib::wakeUp() -
589{ -
590 Q_D(QEventDispatcherGlib);
executed (the execution status of this line is deduced): QEventDispatcherGlibPrivate * const d = d_func();
-
591 d->postEventSource->serialNumber.ref();
executed (the execution status of this line is deduced): d->postEventSource->serialNumber.ref();
-
592 g_main_context_wakeup(d->mainContext);
executed (the execution status of this line is deduced): g_main_context_wakeup(d->mainContext);
-
593}
executed: }
Execution Count:546042
546042
594 -
595void QEventDispatcherGlib::flush() -
596{ -
597} -
598 -
599bool QEventDispatcherGlib::versionSupported() -
600{ -
601#if !defined(GLIB_MAJOR_VERSION) || !defined(GLIB_MINOR_VERSION) || !defined(GLIB_MICRO_VERSION) -
602 return false; -
603#else -
604 return ((GLIB_MAJOR_VERSION << 16) + (GLIB_MINOR_VERSION << 8) + GLIB_MICRO_VERSION) >= 0x020301;
executed: return ((2 << 16) + (24 << 8) + 2) >= 0x020301;
Execution Count:1717525
1717525
605#endif -
606} -
607 -
608QEventDispatcherGlib::QEventDispatcherGlib(QEventDispatcherGlibPrivate &dd, QObject *parent) -
609 : QAbstractEventDispatcher(dd, parent) -
610{ -
611}
executed: }
Execution Count:105
105
612 -
613QT_END_NAMESPACE -
614 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial