kernel/qeventloop.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5QEventLoop::QEventLoop(QObject *parent) -
6 : QObject(*new QEventLoopPrivate, parent) -
7{ -
8 QEventLoopPrivate * const d = d_func(); -
9 if (!QCoreApplication::instance()) {
partially evaluated: !QCoreApplication::instance()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2677
0-2677
10 QMessageLogger("kernel/qeventloop.cpp", 105, __PRETTY_FUNCTION__).warning("QEventLoop: Cannot be used without QApplication"); -
11 } else if (!d->threadData->eventDispatcher) {
never executed: }
evaluated: !d->threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2678
0-2678
12 QThreadPrivate::createEventDispatcher(d->threadData); -
13 }
executed: }
Execution Count:2
2
14} -
15 -
16 -
17 -
18 -
19QEventLoop::~QEventLoop() -
20{ } -
21bool QEventLoop::processEvents(ProcessEventsFlags flags) -
22{ -
23 QEventLoopPrivate * const d = d_func(); -
24 if (!d->threadData->eventDispatcher)
partially evaluated: !d->threadData->eventDispatcher
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:60448
0-60448
25 return false;
never executed: return false;
0
26 return d->threadData->eventDispatcher->processEvents(flags);
executed: return d->threadData->eventDispatcher->processEvents(flags);
Execution Count:60446
60446
27} -
28int QEventLoop::exec(ProcessEventsFlags flags) -
29{ -
30 QEventLoopPrivate * const d = d_func(); -
31 -
32 QMutexLocker locker(&static_cast<QThreadPrivate *>(QObjectPrivate::get(d->threadData->thread))->mutex); -
33 if (d->threadData->quitNow)
evaluated: d->threadData->quitNow
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:2699
8-2699
34 return -1;
executed: return -1;
Execution Count:8
8
35 -
36 if (d->inExec) {
evaluated: d->inExec
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2698
1-2698
37 QMessageLogger("kernel/qeventloop.cpp", 171, __PRETTY_FUNCTION__).warning("QEventLoop::exec: instance %p has already called exec()", this); -
38 return -1;
executed: return -1;
Execution Count:1
1
39 } -
40 -
41 struct LoopReference { -
42 QEventLoopPrivate *d; -
43 QMutexLocker &locker; -
44 -
45 bool exceptionCaught; -
46 LoopReference(QEventLoopPrivate *d, QMutexLocker &locker) : d(d), locker(locker), exceptionCaught(true) -
47 { -
48 d->inExec = true; -
49 d->exit = false; -
50 ++d->threadData->loopLevel; -
51 d->threadData->eventLoops.push(d->q_func()); -
52 locker.unlock(); -
53 }
executed: }
Execution Count:2698
2698
54 -
55 ~LoopReference() -
56 { -
57 if (exceptionCaught) {
partially evaluated: exceptionCaught
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2699
0-2699
58 QMessageLogger("kernel/qeventloop.cpp", 192, __PRETTY_FUNCTION__).warning("Qt has caught an exception thrown from an event handler. Throwing\n" -
59 "exceptions from an event handler is not supported in Qt. You must\n" -
60 "reimplement QApplication::notify() and catch all exceptions there.\n"); -
61 }
never executed: }
0
62 locker.relock(); -
63 QEventLoop *eventLoop = d->threadData->eventLoops.pop(); -
64 qt_noop(); -
65 (void)eventLoop;; -
66 d->inExec = false; -
67 --d->threadData->loopLevel; -
68 }
executed: }
Execution Count:2699
2699
69 }; -
70 LoopReference ref(d, locker); -
71 -
72 -
73 QCoreApplication *app = QCoreApplication::instance(); -
74 if (app && app->thread() == thread())
partially evaluated: app
TRUEFALSE
yes
Evaluation Count:2698
no
Evaluation Count:0
evaluated: app->thread() == thread()
TRUEFALSE
yes
Evaluation Count:1990
yes
Evaluation Count:708
0-2698
75 QCoreApplication::removePostedEvents(app, QEvent::Quit);
executed: QCoreApplication::removePostedEvents(app, QEvent::Quit);
Execution Count:1990
1990
76 -
77 while (!d->exit)
evaluated: !d->exit
TRUEFALSE
yes
Evaluation Count:60439
yes
Evaluation Count:2699
2699-60439
78 processEvents(flags | WaitForMoreEvents | EventLoopExec);
executed: processEvents(flags | WaitForMoreEvents | EventLoopExec);
Execution Count:60438
60438
79 -
80 ref.exceptionCaught = false; -
81 return d->returnCode;
executed: return d->returnCode;
Execution Count:2699
2699
82} -
83void QEventLoop::processEvents(ProcessEventsFlags flags, int maxTime) -
84{ -
85 QEventLoopPrivate * const d = d_func(); -
86 if (!d->threadData->eventDispatcher)
never evaluated: !d->threadData->eventDispatcher
0
87 return;
never executed: return;
0
88 -
89 QElapsedTimer start; -
90 start.start(); -
91 while (processEvents(flags & ~WaitForMoreEvents)) {
never evaluated: processEvents(flags & ~WaitForMoreEvents)
0
92 if (start.elapsed() > maxTime)
never evaluated: start.elapsed() > maxTime
0
93 break;
never executed: break;
0
94 }
never executed: }
0
95}
never executed: }
0
96void QEventLoop::exit(int returnCode) -
97{ -
98 QEventLoopPrivate * const d = d_func(); -
99 if (!d->threadData->eventDispatcher)
partially evaluated: !d->threadData->eventDispatcher
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2709
0-2709
100 return;
never executed: return;
0
101 -
102 d->returnCode = returnCode; -
103 d->exit = true; -
104 d->threadData->eventDispatcher->interrupt(); -
105}
executed: }
Execution Count:2709
2709
106bool QEventLoop::isRunning() const -
107{ -
108 const QEventLoopPrivate * const d = d_func(); -
109 return !d->exit;
executed: return !d->exit;
Execution Count:8
8
110} -
111 -
112 -
113 -
114 -
115 -
116 -
117void QEventLoop::wakeUp() -
118{ -
119 QEventLoopPrivate * const d = d_func(); -
120 if (!d->threadData->eventDispatcher)
partially evaluated: !d->threadData->eventDispatcher
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
121 return;
never executed: return;
0
122 d->threadData->eventDispatcher->wakeUp(); -
123}
executed: }
Execution Count:1
1
124 -
125 -
126 -
127 -
128 -
129bool QEventLoop::event(QEvent *event) -
130{ -
131 if (event->type() == QEvent::Quit) {
evaluated: event->type() == QEvent::Quit
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:163
2-163
132 quit(); -
133 return true;
executed: return true;
Execution Count:2
2
134 } else { -
135 return QObject::event(event);
executed: return QObject::event(event);
Execution Count:163
163
136 } -
137} -
138void QEventLoop::quit() -
139{ exit(0); }
executed: exit(0);
Execution Count:380
380
140 -
141 -
142class QEventLoopLockerPrivate -
143{ -
144public: -
145 explicit QEventLoopLockerPrivate(QEventLoopPrivate *loop) -
146 : loop(loop), type(EventLoop) -
147 { -
148 loop->ref(); -
149 }
executed: }
Execution Count:11
11
150 -
151 explicit QEventLoopLockerPrivate(QThreadPrivate *thread) -
152 : thread(thread), type(Thread) -
153 { -
154 thread->ref(); -
155 }
executed: }
Execution Count:2
2
156 -
157 explicit QEventLoopLockerPrivate(QCoreApplicationPrivate *app) -
158 : app(app), type(Application) -
159 { -
160 app->ref(); -
161 }
executed: }
Execution Count:6
6
162 -
163 ~QEventLoopLockerPrivate() -
164 { -
165 switch (type) -
166 { -
167 case EventLoop: -
168 loop->deref(); -
169 break;
executed: break;
Execution Count:11
11
170 case Thread: -
171 thread->deref(); -
172 break;
executed: break;
Execution Count:1
1
173 default: -
174 app->deref(); -
175 break;
executed: break;
Execution Count:6
6
176 } -
177 }
executed: }
Execution Count:18
18
178 -
179private: -
180 union { -
181 QEventLoopPrivate * loop; -
182 QThreadPrivate * thread; -
183 QCoreApplicationPrivate * app; -
184 }; -
185 enum Type { -
186 EventLoop, -
187 Thread, -
188 Application -
189 }; -
190 const Type type; -
191}; -
192QEventLoopLocker::QEventLoopLocker() -
193 : d_ptr(new QEventLoopLockerPrivate(static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance())))) -
194{ -
195 -
196}
executed: }
Execution Count:6
6
197QEventLoopLocker::QEventLoopLocker(QEventLoop *loop) -
198 : d_ptr(new QEventLoopLockerPrivate(static_cast<QEventLoopPrivate*>(QObjectPrivate::get(loop)))) -
199{ -
200 -
201}
executed: }
Execution Count:11
11
202QEventLoopLocker::QEventLoopLocker(QThread *thread) -
203 : d_ptr(new QEventLoopLockerPrivate(static_cast<QThreadPrivate*>(QObjectPrivate::get(thread)))) -
204{ -
205 -
206}
executed: }
Execution Count:2
2
207 -
208 -
209 -
210 -
211QEventLoopLocker::~QEventLoopLocker() -
212{ -
213 delete d_ptr; -
214}
executed: }
Execution Count:18
18
215 -
216 -
217 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial