qtconcurrentthreadengine.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6namespace QtConcurrent { -
7 -
8ThreadEngineBarrier::ThreadEngineBarrier() -
9:count(0) { }
executed: }
Execution Count:81048
81048
10 -
11void ThreadEngineBarrier::acquire() -
12{ -
13 for(;;) { -
14 int localCount = count.load(); -
15 if (localCount < 0) {
evaluated: localCount < 0
TRUEFALSE
yes
Evaluation Count:614
yes
Evaluation Count:543775
614-543775
16 if (count.testAndSetOrdered(localCount, localCount -1))
evaluated: count.testAndSetOrdered(localCount, localCount -1)
TRUEFALSE
yes
Evaluation Count:608
yes
Evaluation Count:15
15-608
17 return;
executed: return;
Execution Count:608
608
18 } else {
executed: }
Execution Count:15
15
19 if (count.testAndSetOrdered(localCount, localCount + 1))
evaluated: count.testAndSetOrdered(localCount, localCount + 1)
TRUEFALSE
yes
Evaluation Count:531495
yes
Evaluation Count:17668
17668-531495
20 return;
executed: return;
Execution Count:531450
531450
21 }
executed: }
Execution Count:17602
17602
22 } -
23}
never executed: }
0
24 -
25int ThreadEngineBarrier::release() -
26{ -
27 for(;;) { -
28 int localCount = count.load(); -
29 if (localCount == -1) {
evaluated: localCount == -1
TRUEFALSE
yes
Evaluation Count:504
yes
Evaluation Count:544363
504-544363
30 if (count.testAndSetOrdered(-1, 0)) {
partially evaluated: count.testAndSetOrdered(-1, 0)
TRUEFALSE
yes
Evaluation Count:504
no
Evaluation Count:0
0-504
31 semaphore.release(); -
32 return 0;
executed: return 0;
Execution Count:504
504
33 } -
34 } else if (localCount < 0) {
never executed: }
evaluated: localCount < 0
TRUEFALSE
yes
Evaluation Count:2151
yes
Evaluation Count:542550
0-542550
35 if (count.testAndSetOrdered(localCount, localCount + 1))
evaluated: count.testAndSetOrdered(localCount, localCount + 1)
TRUEFALSE
yes
Evaluation Count:2126
yes
Evaluation Count:46
46-2126
36 return qAbs(localCount + 1);
executed: return qAbs(localCount + 1);
Execution Count:2126
2126
37 } else {
executed: }
Execution Count:46
46
38 if (count.testAndSetOrdered(localCount, localCount - 1))
evaluated: count.testAndSetOrdered(localCount, localCount - 1)
TRUEFALSE
yes
Evaluation Count:528894
yes
Evaluation Count:20014
20014-528894
39 return localCount - 1;
executed: return localCount - 1;
Execution Count:528399
528399
40 }
executed: }
Execution Count:19893
19893
41 } -
42}
never executed: }
0
43 -
44 -
45void ThreadEngineBarrier::wait() -
46{ -
47 for(;;) { -
48 int localCount = count.load(); -
49 if (localCount == 0)
evaluated: localCount == 0
TRUEFALSE
yes
Evaluation Count:20047
yes
Evaluation Count:520
520-20047
50 return;
executed: return;
Execution Count:20047
20047
51 -
52 qt_noop(); -
53 if (count.testAndSetOrdered(localCount, -localCount)) {
evaluated: count.testAndSetOrdered(localCount, -localCount)
TRUEFALSE
yes
Evaluation Count:504
yes
Evaluation Count:16
16-504
54 semaphore.acquire(); -
55 return;
executed: return;
Execution Count:504
504
56 } -
57 }
executed: }
Execution Count:16
16
58}
never executed: }
0
59 -
60int ThreadEngineBarrier::currentCount() -
61{ -
62 return count.load();
never executed: return count.load();
0
63} -
64 -
65 -
66 -
67bool ThreadEngineBarrier::releaseUnlessLast() -
68{ -
69 for(;;) { -
70 int localCount = count.load(); -
71 if (qAbs(localCount) == 1) {
evaluated: qAbs(localCount) == 1
TRUEFALSE
yes
Evaluation Count:1532
yes
Evaluation Count:576
576-1532
72 return false;
executed: return false;
Execution Count:1532
1532
73 } else if (localCount < 0) {
evaluated: localCount < 0
TRUEFALSE
yes
Evaluation Count:236
yes
Evaluation Count:340
236-340
74 if (count.testAndSetOrdered(localCount, localCount + 1))
evaluated: count.testAndSetOrdered(localCount, localCount + 1)
TRUEFALSE
yes
Evaluation Count:236
yes
Evaluation Count:1
1-236
75 return true;
executed: return true;
Execution Count:236
236
76 } else {
executed: }
Execution Count:1
1
77 if (count.testAndSetOrdered(localCount, localCount - 1))
evaluated: count.testAndSetOrdered(localCount, localCount - 1)
TRUEFALSE
yes
Evaluation Count:337
yes
Evaluation Count:4
4-337
78 return true;
executed: return true;
Execution Count:337
337
79 }
executed: }
Execution Count:4
4
80 } -
81}
never executed: }
0
82 -
83ThreadEngineBase::ThreadEngineBase() -
84:futureInterface(0), threadPool(QThreadPool::globalInstance()) -
85{ -
86 setAutoDelete(false); -
87}
executed: }
Execution Count:81048
81048
88 -
89ThreadEngineBase::~ThreadEngineBase() {} -
90 -
91void ThreadEngineBase::startSingleThreaded() -
92{ -
93 start(); -
94 while (threadFunction() != ThreadFinished)
partially evaluated: threadFunction() != ThreadFinished
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
95 ;
never executed: ;
0
96 finish(); -
97}
executed: }
Execution Count:1
1
98 -
99void ThreadEngineBase::startBlocking() -
100{ -
101 start(); -
102 barrier.acquire(); -
103 startThreads(); -
104 -
105 bool throttled = false; -
106 -
107 try { -
108 -
109 while (threadFunction() == ThrottleThread) {
evaluated: threadFunction() == ThrottleThread
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:20536
11-20536
110 if (threadThrottleExit()) {
partially evaluated: threadThrottleExit()
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-11
111 throttled = true; -
112 break;
executed: break;
Execution Count:11
11
113 } -
114 }
never executed: }
0
115 -
116 } catch (QException &e) {
executed: }
Execution Count:20547
20547
117 handleException(e); -
118 } catch (...) {
executed: }
Execution Count:2
2
119 handleException(QUnhandledException()); -
120 }
executed: }
Execution Count:2
2
121 -
122 -
123 if (throttled == false) {
evaluated: throttled == false
TRUEFALSE
yes
Evaluation Count:20540
yes
Evaluation Count:11
11-20540
124 barrier.release(); -
125 }
executed: }
Execution Count:20540
20540
126 -
127 barrier.wait(); -
128 finish(); -
129 exceptionStore.throwPossibleException(); -
130}
executed: }
Execution Count:20547
20547
131 -
132void ThreadEngineBase::startThread() -
133{ -
134 startThreadInternal(); -
135}
executed: }
Execution Count:77754
77754
136 -
137void ThreadEngineBase::acquireBarrierSemaphore() -
138{ -
139 barrier.acquire(); -
140}
executed: }
Execution Count:60497
60497
141 -
142bool ThreadEngineBase::isCanceled() -
143{ -
144 if (futureInterface)
evaluated: futureInterface
TRUEFALSE
yes
Evaluation Count:754339
yes
Evaluation Count:143551
143551-754339
145 return futureInterface->isCanceled();
executed: return futureInterface->isCanceled();
Execution Count:753904
753904
146 else -
147 return false;
executed: return false;
Execution Count:143040
143040
148} -
149 -
150void ThreadEngineBase::waitForResume() -
151{ -
152 if (futureInterface)
evaluated: futureInterface
TRUEFALSE
yes
Evaluation Count:24235
yes
Evaluation Count:56416
24235-56416
153 futureInterface->waitForResume();
executed: futureInterface->waitForResume();
Execution Count:24081
24081
154}
executed: }
Execution Count:80058
80058
155 -
156bool ThreadEngineBase::isProgressReportingEnabled() -
157{ -
158 -
159 return (futureInterface != 0);
executed: return (futureInterface != 0);
Execution Count:20910
20910
160} -
161 -
162void ThreadEngineBase::setProgressValue(int progress) -
163{ -
164 if (futureInterface)
partially evaluated: futureInterface
TRUEFALSE
yes
Evaluation Count:23851
no
Evaluation Count:0
0-23851
165 futureInterface->setProgressValue(progress);
executed: futureInterface->setProgressValue(progress);
Execution Count:23764
23764
166}
executed: }
Execution Count:23855
23855
167 -
168void ThreadEngineBase::setProgressRange(int minimum, int maximum) -
169{ -
170 if (futureInterface)
partially evaluated: futureInterface
TRUEFALSE
yes
Evaluation Count:255
no
Evaluation Count:0
0-255
171 futureInterface->setProgressRange(minimum, maximum);
executed: futureInterface->setProgressRange(minimum, maximum);
Execution Count:255
255
172}
executed: }
Execution Count:255
255
173 -
174bool ThreadEngineBase::startThreadInternal() -
175{ -
176 if (this->isCanceled())
partially evaluated: this->isCanceled()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:448054
0-448054
177 return false;
never executed: return false;
0
178 -
179 barrier.acquire(); -
180 if (!threadPool->tryStart(this)) {
evaluated: !threadPool->tryStart(this)
TRUEFALSE
yes
Evaluation Count:161899
yes
Evaluation Count:288213
161899-288213
181 barrier.release(); -
182 return false;
executed: return false;
Execution Count:162843
162843
183 } -
184 return true;
executed: return true;
Execution Count:288214
288214
185} -
186 -
187void ThreadEngineBase::startThreads() -
188{ -
189 while (shouldStartThread() && startThreadInternal())
evaluated: startThreadInternal()
TRUEFALSE
yes
Evaluation Count:288139
yes
Evaluation Count:85040
evaluated: shouldStartThread()
TRUEFALSE
yes
Evaluation Count:372276
yes
Evaluation Count:283307
85040-372276
190 ;
executed: ;
Execution Count:288139
288139
191}
executed: }
Execution Count:368108
368108
192 -
193void ThreadEngineBase::threadExit() -
194{ -
195 const bool asynchronous = futureInterface != 0; -
196 const int lastThread = (barrier.release() == 0); -
197 -
198 if (lastThread && asynchronous)
evaluated: lastThread
TRUEFALSE
yes
Evaluation Count:60982
yes
Evaluation Count:286776
evaluated: asynchronous
TRUEFALSE
yes
Evaluation Count:60479
yes
Evaluation Count:505
505-286776
199 this->asynchronousFinish();
executed: this->asynchronousFinish();
Execution Count:60473
60473
200}
executed: }
Execution Count:347751
347751
201 -
202 -
203 -
204 -
205bool ThreadEngineBase::threadThrottleExit() -
206{ -
207 return barrier.releaseUnlessLast();
executed: return barrier.releaseUnlessLast();
Execution Count:2104
2104
208} -
209 -
210void ThreadEngineBase::run() -
211{ -
212 if (this->isCanceled()) {
evaluated: this->isCanceled()
TRUEFALSE
yes
Evaluation Count:96
yes
Evaluation Count:347773
96-347773
213 threadExit(); -
214 return;
executed: return;
Execution Count:96
96
215 } -
216 -
217 startThreads(); -
218 -
219 -
220 try { -
221 -
222 while (threadFunction() == ThrottleThread) {
evaluated: threadFunction() == ThrottleThread
TRUEFALSE
yes
Evaluation Count:2094
yes
Evaluation Count:346399
2094-346399
223 -
224 -
225 -
226 -
227 if (threadThrottleExit())
evaluated: threadThrottleExit()
TRUEFALSE
yes
Evaluation Count:561
yes
Evaluation Count:1532
561-1532
228 return;
executed: return;
Execution Count:560
560
229 }
executed: }
Execution Count:1532
1532
230 -
231 -
232 } catch (QException &e) {
executed: }
Execution Count:346385
346385
233 handleException(e); -
234 } catch (...) {
executed: }
Execution Count:20
20
235 handleException(QUnhandledException()); -
236 }
executed: }
Execution Count:24
24
237 -
238 threadExit(); -
239}
executed: }
Execution Count:347662
347662
240 -
241 -
242 -
243void ThreadEngineBase::handleException(const QException &exception) -
244{ -
245 if (futureInterface)
evaluated: futureInterface
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:35
12-35
246 futureInterface->reportException(exception);
executed: futureInterface->reportException(exception);
Execution Count:12
12
247 else -
248 exceptionStore.setException(exception);
executed: exceptionStore.setException(exception);
Execution Count:35
35
249} -
250 -
251 -
252 -
253} -
254 -
255 -
256 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial