Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | QReadWriteLock::QReadWriteLock(RecursionMode recursionMode) | - |
7 | : d(new QReadWriteLockPrivate(recursionMode)) | - |
8 | { } executed: } Execution Count:89833 | 89833 |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | QReadWriteLock::~QReadWriteLock() | - |
17 | { | - |
18 | delete d; | - |
19 | } executed: } Execution Count:90794 | 90794 |
20 | void QReadWriteLock::lockForRead() | - |
21 | { | - |
22 | QMutexLocker lock(&d->mutex); | - |
23 | | - |
24 | Qt::HANDLE self = 0; | - |
25 | if (d->recursive) { evaluated: d->recursive yes Evaluation Count:3 | yes Evaluation Count:1813605 |
| 3-1813605 |
26 | self = QThread::currentThreadId(); | - |
27 | | - |
28 | QHash<Qt::HANDLE, int>::iterator it = d->currentReaders.find(self); | - |
29 | if (it != d->currentReaders.end()) { partially evaluated: it != d->currentReaders.end() no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
30 | ++it.value(); | - |
31 | ++d->accessCount; | - |
32 | qt_noop(); | - |
33 | | - |
34 | return; | 0 |
35 | } | - |
36 | } executed: } Execution Count:3 | 3 |
37 | | - |
38 | while (d->accessCount < 0 || d->waitingWriters) { evaluated: d->accessCount < 0 yes Evaluation Count:2793 | yes Evaluation Count:1820894 |
evaluated: d->waitingWriters yes Evaluation Count:7286 | yes Evaluation Count:1813608 |
| 2793-1820894 |
39 | ++d->waitingReaders; | - |
40 | d->readerWait.wait(&d->mutex); | - |
41 | --d->waitingReaders; | - |
42 | } executed: } Execution Count:10079 | 10079 |
43 | if (d->recursive) evaluated: d->recursive yes Evaluation Count:3 | yes Evaluation Count:1813605 |
| 3-1813605 |
44 | d->currentReaders.insert(self, 1); executed: d->currentReaders.insert(self, 1); Execution Count:3 | 3 |
45 | | - |
46 | ++d->accessCount; | - |
47 | qt_noop(); | - |
48 | } executed: } Execution Count:1813608 | 1813608 |
49 | bool QReadWriteLock::tryLockForRead() | - |
50 | { | - |
51 | QMutexLocker lock(&d->mutex); | - |
52 | | - |
53 | Qt::HANDLE self = 0; | - |
54 | if (d->recursive) { evaluated: d->recursive yes Evaluation Count:36 | yes Evaluation Count:7 |
| 7-36 |
55 | self = QThread::currentThreadId(); | - |
56 | | - |
57 | QHash<Qt::HANDLE, int>::iterator it = d->currentReaders.find(self); | - |
58 | if (it != d->currentReaders.end()) { evaluated: it != d->currentReaders.end() yes Evaluation Count:11 | yes Evaluation Count:25 |
| 11-25 |
59 | ++it.value(); | - |
60 | ++d->accessCount; | - |
61 | qt_noop(); | - |
62 | | - |
63 | return true; executed: return true; Execution Count:11 | 11 |
64 | } | - |
65 | } executed: } Execution Count:25 | 25 |
66 | | - |
67 | if (d->accessCount < 0) evaluated: d->accessCount < 0 yes Evaluation Count:23 | yes Evaluation Count:9 |
| 9-23 |
68 | return false; executed: return false; Execution Count:23 | 23 |
69 | if (d->recursive) evaluated: d->recursive yes Evaluation Count:4 | yes Evaluation Count:5 |
| 4-5 |
70 | d->currentReaders.insert(self, 1); executed: d->currentReaders.insert(self, 1); Execution Count:4 | 4 |
71 | | - |
72 | ++d->accessCount; | - |
73 | qt_noop(); | - |
74 | | - |
75 | return true; executed: return true; Execution Count:9 | 9 |
76 | } | - |
77 | bool QReadWriteLock::tryLockForRead(int timeout) | - |
78 | { | - |
79 | QMutexLocker lock(&d->mutex); | - |
80 | | - |
81 | Qt::HANDLE self = 0; | - |
82 | if (d->recursive) { partially evaluated: d->recursive no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
83 | self = QThread::currentThreadId(); | - |
84 | | - |
85 | QHash<Qt::HANDLE, int>::iterator it = d->currentReaders.find(self); | - |
86 | if (it != d->currentReaders.end()) { never evaluated: it != d->currentReaders.end() | 0 |
87 | ++it.value(); | - |
88 | ++d->accessCount; | - |
89 | qt_noop(); | - |
90 | | - |
91 | return true; never executed: return true; | 0 |
92 | } | - |
93 | } | 0 |
94 | | - |
95 | while (d->accessCount < 0 || d->waitingWriters) { evaluated: d->accessCount < 0 yes Evaluation Count:1 | yes Evaluation Count:2 |
partially evaluated: d->waitingWriters no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
96 | ++d->waitingReaders; | - |
97 | bool success = d->readerWait.wait(&d->mutex, timeout < 0 ? (9223372036854775807L * 2UL + 1UL) : ulong(timeout)); | - |
98 | --d->waitingReaders; | - |
99 | if (!success) partially evaluated: !success yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
100 | return false; executed: return false; Execution Count:1 | 1 |
101 | } | 0 |
102 | if (d->recursive) partially evaluated: d->recursive no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
103 | d->currentReaders.insert(self, 1); never executed: d->currentReaders.insert(self, 1); | 0 |
104 | | - |
105 | ++d->accessCount; | - |
106 | qt_noop(); | - |
107 | | - |
108 | return true; executed: return true; Execution Count:2 | 2 |
109 | } | - |
110 | void QReadWriteLock::lockForWrite() | - |
111 | { | - |
112 | QMutexLocker lock(&d->mutex); | - |
113 | | - |
114 | Qt::HANDLE self = 0; | - |
115 | if (d->recursive) { evaluated: d->recursive yes Evaluation Count:4 | yes Evaluation Count:1169355 |
| 4-1169355 |
116 | self = QThread::currentThreadId(); | - |
117 | | - |
118 | if (d->currentWriter == self) { partially evaluated: d->currentWriter == self no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
119 | --d->accessCount; | - |
120 | qt_noop(); | - |
121 | | - |
122 | return; | 0 |
123 | } | - |
124 | } executed: } Execution Count:4 | 4 |
125 | | - |
126 | while (d->accessCount != 0) { evaluated: d->accessCount != 0 yes Evaluation Count:152141 | yes Evaluation Count:1169359 |
| 152141-1169359 |
127 | ++d->waitingWriters; | - |
128 | d->writerWait.wait(&d->mutex); | - |
129 | --d->waitingWriters; | - |
130 | } executed: } Execution Count:152141 | 152141 |
131 | if (d->recursive) evaluated: d->recursive yes Evaluation Count:4 | yes Evaluation Count:1169355 |
| 4-1169355 |
132 | d->currentWriter = self; executed: d->currentWriter = self; Execution Count:4 | 4 |
133 | | - |
134 | --d->accessCount; | - |
135 | qt_noop(); | - |
136 | } executed: } Execution Count:1169359 | 1169359 |
137 | bool QReadWriteLock::tryLockForWrite() | - |
138 | { | - |
139 | QMutexLocker lock(&d->mutex); | - |
140 | | - |
141 | Qt::HANDLE self = 0; | - |
142 | if (d->recursive) { evaluated: d->recursive yes Evaluation Count:39 | yes Evaluation Count:23 |
| 23-39 |
143 | self = QThread::currentThreadId(); | - |
144 | | - |
145 | if (d->currentWriter == self) { evaluated: d->currentWriter == self yes Evaluation Count:12 | yes Evaluation Count:27 |
| 12-27 |
146 | --d->accessCount; | - |
147 | qt_noop(); | - |
148 | | - |
149 | return true; executed: return true; Execution Count:12 | 12 |
150 | } | - |
151 | } executed: } Execution Count:27 | 27 |
152 | | - |
153 | if (d->accessCount != 0) evaluated: d->accessCount != 0 yes Evaluation Count:32 | yes Evaluation Count:18 |
| 18-32 |
154 | return false; executed: return false; Execution Count:32 | 32 |
155 | if (d->recursive) evaluated: d->recursive yes Evaluation Count:5 | yes Evaluation Count:13 |
| 5-13 |
156 | d->currentWriter = self; executed: d->currentWriter = self; Execution Count:5 | 5 |
157 | | - |
158 | --d->accessCount; | - |
159 | qt_noop(); | - |
160 | | - |
161 | | - |
162 | return true; executed: return true; Execution Count:18 | 18 |
163 | } | - |
164 | bool QReadWriteLock::tryLockForWrite(int timeout) | - |
165 | { | - |
166 | QMutexLocker lock(&d->mutex); | - |
167 | | - |
168 | Qt::HANDLE self = 0; | - |
169 | if (d->recursive) { partially evaluated: d->recursive no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
170 | self = QThread::currentThreadId(); | - |
171 | | - |
172 | if (d->currentWriter == self) { never evaluated: d->currentWriter == self | 0 |
173 | --d->accessCount; | - |
174 | qt_noop(); | - |
175 | | - |
176 | return true; never executed: return true; | 0 |
177 | } | - |
178 | } | 0 |
179 | | - |
180 | while (d->accessCount != 0) { evaluated: d->accessCount != 0 yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
181 | ++d->waitingWriters; | - |
182 | bool success = d->writerWait.wait(&d->mutex, timeout < 0 ? (9223372036854775807L * 2UL + 1UL) : ulong(timeout)); | - |
183 | --d->waitingWriters; | - |
184 | | - |
185 | if (!success) partially evaluated: !success yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
186 | return false; executed: return false; Execution Count:1 | 1 |
187 | } | 0 |
188 | if (d->recursive) partially evaluated: d->recursive no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
189 | d->currentWriter = self; never executed: d->currentWriter = self; | 0 |
190 | | - |
191 | --d->accessCount; | - |
192 | qt_noop(); | - |
193 | | - |
194 | | - |
195 | return true; executed: return true; Execution Count:1 | 1 |
196 | } | - |
197 | void QReadWriteLock::unlock() | - |
198 | { | - |
199 | QMutexLocker lock(&d->mutex); | - |
200 | | - |
201 | qt_noop(); | - |
202 | | - |
203 | bool unlocked = false; | - |
204 | if (d->accessCount > 0) { evaluated: d->accessCount > 0 yes Evaluation Count:1813630 | yes Evaluation Count:1169390 |
| 1169390-1813630 |
205 | | - |
206 | if (d->recursive) { evaluated: d->recursive yes Evaluation Count:18 | yes Evaluation Count:1813612 |
| 18-1813612 |
207 | Qt::HANDLE self = QThread::currentThreadId(); | - |
208 | QHash<Qt::HANDLE, int>::iterator it = d->currentReaders.find(self); | - |
209 | if (it != d->currentReaders.end()) { partially evaluated: it != d->currentReaders.end() yes Evaluation Count:18 | no Evaluation Count:0 |
| 0-18 |
210 | if (--it.value() <= 0) evaluated: --it.value() <= 0 yes Evaluation Count:7 | yes Evaluation Count:11 |
| 7-11 |
211 | d->currentReaders.erase(it); executed: d->currentReaders.erase(it); Execution Count:7 | 7 |
212 | } executed: } Execution Count:18 | 18 |
213 | } executed: } Execution Count:18 | 18 |
214 | | - |
215 | unlocked = --d->accessCount == 0; | - |
216 | } else if (d->accessCount < 0 && ++d->accessCount == 0) { executed: } Execution Count:1813630 partially evaluated: d->accessCount < 0 yes Evaluation Count:1169390 | no Evaluation Count:0 |
evaluated: ++d->accessCount == 0 yes Evaluation Count:1169378 | yes Evaluation Count:12 |
| 0-1813630 |
217 | | - |
218 | unlocked = true; | - |
219 | d->currentWriter = 0; | - |
220 | } executed: } Execution Count:1169378 | 1169378 |
221 | | - |
222 | if (unlocked) { evaluated: unlocked yes Evaluation Count:2805032 | yes Evaluation Count:177987 |
| 177987-2805032 |
223 | if (d->waitingWriters) { evaluated: d->waitingWriters yes Evaluation Count:152442 | yes Evaluation Count:2652591 |
| 152442-2652591 |
224 | d->writerWait.wakeOne(); | - |
225 | } else if (d->waitingReaders) { executed: } Execution Count:152442 evaluated: d->waitingReaders yes Evaluation Count:32113 | yes Evaluation Count:2620478 |
| 32113-2620478 |
226 | d->readerWait.wakeAll(); | - |
227 | } executed: } Execution Count:32113 | 32113 |
228 | } | - |
229 | } executed: } Execution Count:2983020 | 2983020 |
230 | | - |
231 | | - |
| | |