| Line | Source Code | Coverage |
|---|
| 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 | // qfutureinterface.h included from qfuture.h | - |
| 43 | #include "qfuture.h" | - |
| 44 | | - |
| 45 | #ifndef QT_NO_QFUTURE | - |
| 46 | | - |
| 47 | #include "qfutureinterface_p.h" | - |
| 48 | | - |
| 49 | #include <QtCore/qatomic.h> | - |
| 50 | #include <QtCore/qthread.h> | - |
| 51 | #include <QtCore/qthreadpool.h> | - |
| 52 | #include <private/qthreadpool_p.h> | - |
| 53 | | - |
| 54 | QT_BEGIN_NAMESPACE | - |
| 55 | | - |
| 56 | enum { | - |
| 57 | MaxProgressEmitsPerSecond = 25 | - |
| 58 | }; | - |
| 59 | | - |
| 60 | QFutureInterfaceBase::QFutureInterfaceBase(State initialState) | - |
| 61 | : d(new QFutureInterfaceBasePrivate(initialState)) | - |
| 62 | { } executed: }Execution Count:584761 | 584761 |
| 63 | | - |
| 64 | QFutureInterfaceBase::QFutureInterfaceBase(const QFutureInterfaceBase &other) | - |
| 65 | : d(other.d) | - |
| 66 | { | - |
| 67 | d->refCount.ref(); executed (the execution status of this line is deduced): d->refCount.ref(); | - |
| 68 | } executed: }Execution Count:615827 | 615827 |
| 69 | | - |
| 70 | QFutureInterfaceBase::~QFutureInterfaceBase() | - |
| 71 | { | - |
| 72 | if (!d->refCount.deref()) evaluated: !d->refCount.deref()| yes Evaluation Count:585709 | yes Evaluation Count:615878 |
| 585709-615878 |
| 73 | delete d; executed: delete d;Execution Count:585165 | 585165 |
| 74 | } executed: }Execution Count:1195600 | 1195600 |
| 75 | | - |
| 76 | void QFutureInterfaceBase::cancel() | - |
| 77 | { | - |
| 78 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 79 | if (d->state & Canceled) evaluated: d->state & Canceled| yes Evaluation Count:5 | yes Evaluation Count:1112 |
| 5-1112 |
| 80 | return; executed: return;Execution Count:5 | 5 |
| 81 | | - |
| 82 | d->state = State((d->state & ~Paused) | Canceled); executed (the execution status of this line is deduced): d->state = State((d->state & ~Paused) | Canceled); | - |
| 83 | d->waitCondition.wakeAll(); executed (the execution status of this line is deduced): d->waitCondition.wakeAll(); | - |
| 84 | d->pausedWaitCondition.wakeAll(); executed (the execution status of this line is deduced): d->pausedWaitCondition.wakeAll(); | - |
| 85 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); | - |
| 86 | } executed: }Execution Count:1112 | 1112 |
| 87 | | - |
| 88 | void QFutureInterfaceBase::setPaused(bool paused) | - |
| 89 | { | - |
| 90 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 91 | if (paused) { evaluated: paused| yes Evaluation Count:9 | yes Evaluation Count:9 |
| 9 |
| 92 | d->state = State(d->state | Paused); executed (the execution status of this line is deduced): d->state = State(d->state | Paused); | - |
| 93 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); | - |
| 94 | } else { executed: }Execution Count:9 | 9 |
| 95 | d->state = State(d->state & ~Paused); executed (the execution status of this line is deduced): d->state = State(d->state & ~Paused); | - |
| 96 | d->pausedWaitCondition.wakeAll(); executed (the execution status of this line is deduced): d->pausedWaitCondition.wakeAll(); | - |
| 97 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); | - |
| 98 | } executed: }Execution Count:9 | 9 |
| 99 | } | - |
| 100 | | - |
| 101 | void QFutureInterfaceBase::togglePaused() | - |
| 102 | { | - |
| 103 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 104 | if (d->state & Paused) { evaluated: d->state & Paused| yes Evaluation Count:1 | yes Evaluation Count:7 |
| 1-7 |
| 105 | d->state = State(d->state & ~Paused); executed (the execution status of this line is deduced): d->state = State(d->state & ~Paused); | - |
| 106 | d->pausedWaitCondition.wakeAll(); executed (the execution status of this line is deduced): d->pausedWaitCondition.wakeAll(); | - |
| 107 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); | - |
| 108 | } else { executed: }Execution Count:1 | 1 |
| 109 | d->state = State(d->state | Paused); executed (the execution status of this line is deduced): d->state = State(d->state | Paused); | - |
| 110 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); | - |
| 111 | } executed: }Execution Count:7 | 7 |
| 112 | } | - |
| 113 | | - |
| 114 | void QFutureInterfaceBase::setThrottled(bool enable) | - |
| 115 | { | - |
| 116 | // bail out if we are not changing the state | - |
| 117 | if ((enable && (d->state & Throttled)) || (!enable && !(d->state & Throttled))) evaluated: enable| yes Evaluation Count:2 | yes Evaluation Count:64 |
partially evaluated: (d->state & Throttled)| no Evaluation Count:0 | yes Evaluation Count:2 |
evaluated: !enable| yes Evaluation Count:64 | yes Evaluation Count:2 |
evaluated: !(d->state & Throttled)| yes Evaluation Count:60 | yes Evaluation Count:4 |
| 0-64 |
| 118 | return; executed: return;Execution Count:60 | 60 |
| 119 | | - |
| 120 | // lock and change the state | - |
| 121 | QMutexLocker lock(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker lock(&d->m_mutex); | - |
| 122 | if (enable) { evaluated: enable| yes Evaluation Count:2 | yes Evaluation Count:4 |
| 2-4 |
| 123 | d->state = State(d->state | Throttled); executed (the execution status of this line is deduced): d->state = State(d->state | Throttled); | - |
| 124 | } else { executed: }Execution Count:2 | 2 |
| 125 | d->state = State(d->state & ~Throttled); executed (the execution status of this line is deduced): d->state = State(d->state & ~Throttled); | - |
| 126 | if (!(d->state & Paused)) partially evaluated: !(d->state & Paused)| yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
| 127 | d->pausedWaitCondition.wakeAll(); executed: d->pausedWaitCondition.wakeAll();Execution Count:4 | 4 |
| 128 | } executed: }Execution Count:4 | 4 |
| 129 | } | - |
| 130 | | - |
| 131 | | - |
| 132 | bool QFutureInterfaceBase::isRunning() const | - |
| 133 | { | - |
| 134 | return queryState(Running); executed: return queryState(Running);Execution Count:47 | 47 |
| 135 | } | - |
| 136 | | - |
| 137 | bool QFutureInterfaceBase::isStarted() const | - |
| 138 | { | - |
| 139 | return queryState(Started); executed: return queryState(Started);Execution Count:26 | 26 |
| 140 | } | - |
| 141 | | - |
| 142 | bool QFutureInterfaceBase::isCanceled() const | - |
| 143 | { | - |
| 144 | return queryState(Canceled); executed: return queryState(Canceled);Execution Count:1278110 | 1278110 |
| 145 | } | - |
| 146 | | - |
| 147 | bool QFutureInterfaceBase::isFinished() const | - |
| 148 | { | - |
| 149 | return queryState(Finished); executed: return queryState(Finished);Execution Count:166 | 166 |
| 150 | } | - |
| 151 | | - |
| 152 | bool QFutureInterfaceBase::isPaused() const | - |
| 153 | { | - |
| 154 | return queryState(Paused); executed: return queryState(Paused);Execution Count:50475 | 50475 |
| 155 | } | - |
| 156 | | - |
| 157 | bool QFutureInterfaceBase::isThrottled() const | - |
| 158 | { | - |
| 159 | return queryState(Throttled); executed: return queryState(Throttled);Execution Count:7 | 7 |
| 160 | } | - |
| 161 | | - |
| 162 | bool QFutureInterfaceBase::isResultReadyAt(int index) const | - |
| 163 | { | - |
| 164 | QMutexLocker lock(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker lock(&d->m_mutex); | - |
| 165 | return d->internal_isResultReadyAt(index); executed: return d->internal_isResultReadyAt(index);Execution Count:15004 | 15004 |
| 166 | } | - |
| 167 | | - |
| 168 | bool QFutureInterfaceBase::waitForNextResult() | - |
| 169 | { | - |
| 170 | QMutexLocker lock(&d->m_mutex); never executed (the execution status of this line is deduced): QMutexLocker lock(&d->m_mutex); | - |
| 171 | return d->internal_waitForNextResult(); never executed: return d->internal_waitForNextResult(); | 0 |
| 172 | } | - |
| 173 | | - |
| 174 | void QFutureInterfaceBase::waitForResume() | - |
| 175 | { | - |
| 176 | // return early if possible to avoid taking the mutex lock. | - |
| 177 | if ((d->state & Paused) == false || (d->state & Canceled)) partially evaluated: (d->state & Paused) == false| yes Evaluation Count:23984 | no Evaluation Count:0 |
never evaluated: (d->state & Canceled) | 0-23984 |
| 178 | return; executed: return;Execution Count:23857 | 23857 |
| 179 | | - |
| 180 | QMutexLocker lock(&d->m_mutex); never executed (the execution status of this line is deduced): QMutexLocker lock(&d->m_mutex); | - |
| 181 | if ((d->state & Paused) == false || (d->state & Canceled)) never evaluated: (d->state & Paused) == false never evaluated: (d->state & Canceled) | 0 |
| 182 | return; | 0 |
| 183 | | - |
| 184 | // decrease active thread count since this thread will wait. | - |
| 185 | QThreadPool::globalInstance()->releaseThread(); never executed (the execution status of this line is deduced): QThreadPool::globalInstance()->releaseThread(); | - |
| 186 | | - |
| 187 | d->pausedWaitCondition.wait(&d->m_mutex); never executed (the execution status of this line is deduced): d->pausedWaitCondition.wait(&d->m_mutex); | - |
| 188 | | - |
| 189 | QThreadPool::globalInstance()->reserveThread(); never executed (the execution status of this line is deduced): QThreadPool::globalInstance()->reserveThread(); | - |
| 190 | } | 0 |
| 191 | | - |
| 192 | int QFutureInterfaceBase::progressValue() const | - |
| 193 | { | - |
| 194 | return d->m_progressValue; executed: return d->m_progressValue;Execution Count:17 | 17 |
| 195 | } | - |
| 196 | | - |
| 197 | int QFutureInterfaceBase::progressMinimum() const | - |
| 198 | { | - |
| 199 | return d->m_progressMinimum; executed: return d->m_progressMinimum;Execution Count:12 | 12 |
| 200 | } | - |
| 201 | | - |
| 202 | int QFutureInterfaceBase::progressMaximum() const | - |
| 203 | { | - |
| 204 | return d->m_progressMaximum; executed: return d->m_progressMaximum;Execution Count:12 | 12 |
| 205 | } | - |
| 206 | | - |
| 207 | int QFutureInterfaceBase::resultCount() const | - |
| 208 | { | - |
| 209 | QMutexLocker lock(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker lock(&d->m_mutex); | - |
| 210 | return d->internal_resultCount(); executed: return d->internal_resultCount();Execution Count:3915 | 3915 |
| 211 | } | - |
| 212 | | - |
| 213 | QString QFutureInterfaceBase::progressText() const | - |
| 214 | { | - |
| 215 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 216 | return d->m_progressText; executed: return d->m_progressText;Execution Count:15 | 15 |
| 217 | } | - |
| 218 | | - |
| 219 | bool QFutureInterfaceBase::isProgressUpdateNeeded() const | - |
| 220 | { | - |
| 221 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 222 | return !d->progressTime.isValid() || (d->progressTime.elapsed() > (1000 / MaxProgressEmitsPerSecond)); executed: return !d->progressTime.isValid() || (d->progressTime.elapsed() > (1000 / MaxProgressEmitsPerSecond));Execution Count:120 | 120 |
| 223 | } | - |
| 224 | | - |
| 225 | void QFutureInterfaceBase::reportStarted() | - |
| 226 | { | - |
| 227 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 228 | if ((d->state & Started) || (d->state & Canceled) || (d->state & Finished)) partially evaluated: (d->state & Started)| no Evaluation Count:0 | yes Evaluation Count:583729 |
partially evaluated: (d->state & Canceled)| no Evaluation Count:0 | yes Evaluation Count:584359 |
partially evaluated: (d->state & Finished)| no Evaluation Count:0 | yes Evaluation Count:584624 |
| 0-584624 |
| 229 | return; | 0 |
| 230 | | - |
| 231 | d->setState(State(Started | Running)); executed (the execution status of this line is deduced): d->setState(State(Started | Running)); | - |
| 232 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Started)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Started)); | - |
| 233 | } executed: }Execution Count:582142 | 582142 |
| 234 | | - |
| 235 | void QFutureInterfaceBase::reportCanceled() | - |
| 236 | { | - |
| 237 | cancel(); executed (the execution status of this line is deduced): cancel(); | - |
| 238 | } executed: }Execution Count:3 | 3 |
| 239 | | - |
| 240 | #ifndef QT_NO_EXCEPTIONS | - |
| 241 | void QFutureInterfaceBase::reportException(const QException &exception) | - |
| 242 | { | - |
| 243 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 244 | if ((d->state & Canceled) || (d->state & Finished)) evaluated: (d->state & Canceled)| yes Evaluation Count:9 | yes Evaluation Count:13 |
partially evaluated: (d->state & Finished)| no Evaluation Count:0 | yes Evaluation Count:13 |
| 0-13 |
| 245 | return; executed: return;Execution Count:9 | 9 |
| 246 | | - |
| 247 | d->m_exceptionStore.setException(exception); executed (the execution status of this line is deduced): d->m_exceptionStore.setException(exception); | - |
| 248 | d->state = State(d->state | Canceled); executed (the execution status of this line is deduced): d->state = State(d->state | Canceled); | - |
| 249 | d->waitCondition.wakeAll(); executed (the execution status of this line is deduced): d->waitCondition.wakeAll(); | - |
| 250 | d->pausedWaitCondition.wakeAll(); executed (the execution status of this line is deduced): d->pausedWaitCondition.wakeAll(); | - |
| 251 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); | - |
| 252 | } executed: }Execution Count:13 | 13 |
| 253 | #endif | - |
| 254 | | - |
| 255 | void QFutureInterfaceBase::reportFinished() | - |
| 256 | { | - |
| 257 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 258 | if (!(d->state & Finished)) { partially evaluated: !(d->state & Finished)| yes Evaluation Count:582914 | no Evaluation Count:0 |
| 0-582914 |
| 259 | d->state = State((d->state & ~Running) | Finished); executed (the execution status of this line is deduced): d->state = State((d->state & ~Running) | Finished); | - |
| 260 | d->waitCondition.wakeAll(); executed (the execution status of this line is deduced): d->waitCondition.wakeAll(); | - |
| 261 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Finished)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Finished)); | - |
| 262 | } executed: }Execution Count:581511 | 581511 |
| 263 | } executed: }Execution Count:582066 | 582066 |
| 264 | | - |
| 265 | void QFutureInterfaceBase::setExpectedResultCount(int resultCount) | - |
| 266 | { | - |
| 267 | if (d->manualProgress == false) never evaluated: d->manualProgress == false | 0 |
| 268 | setProgressRange(0, resultCount); never executed: setProgressRange(0, resultCount); | 0 |
| 269 | d->m_expectedResultCount = resultCount; never executed (the execution status of this line is deduced): d->m_expectedResultCount = resultCount; | - |
| 270 | } | 0 |
| 271 | | - |
| 272 | int QFutureInterfaceBase::expectedResultCount() | - |
| 273 | { | - |
| 274 | return d->m_expectedResultCount; never executed: return d->m_expectedResultCount; | 0 |
| 275 | } | - |
| 276 | | - |
| 277 | bool QFutureInterfaceBase::queryState(State state) const | - |
| 278 | { | - |
| 279 | return (d->state & state); executed: return (d->state & state);Execution Count:1845194 | 1845194 |
| 280 | } | - |
| 281 | | - |
| 282 | void QFutureInterfaceBase::waitForResult(int resultIndex) | - |
| 283 | { | - |
| 284 | d->m_exceptionStore.throwPossibleException(); executed (the execution status of this line is deduced): d->m_exceptionStore.throwPossibleException(); | - |
| 285 | | - |
| 286 | QMutexLocker lock(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker lock(&d->m_mutex); | - |
| 287 | if (!(d->state & Running)) evaluated: !(d->state & Running)| yes Evaluation Count:15498 | yes Evaluation Count:263889 |
| 15498-263889 |
| 288 | return; executed: return;Execution Count:15498 | 15498 |
| 289 | lock.unlock(); executed (the execution status of this line is deduced): lock.unlock(); | - |
| 290 | | - |
| 291 | // To avoid deadlocks and reduce the number of threads used, try to | - |
| 292 | // run the runnable in the current thread. | - |
| 293 | QThreadPool::globalInstance()->d_func()->stealRunnable(d->runnable); executed (the execution status of this line is deduced): QThreadPool::globalInstance()->d_func()->stealRunnable(d->runnable); | - |
| 294 | | - |
| 295 | lock.relock(); executed (the execution status of this line is deduced): lock.relock(); | - |
| 296 | | - |
| 297 | if (!(d->state & Running)) evaluated: !(d->state & Running)| yes Evaluation Count:260361 | yes Evaluation Count:3744 |
| 3744-260361 |
| 298 | return; executed: return;Execution Count:260151 | 260151 |
| 299 | | - |
| 300 | const int waitIndex = (resultIndex == -1) ? INT_MAX : resultIndex; evaluated: (resultIndex == -1)| yes Evaluation Count:86 | yes Evaluation Count:3658 |
| 86-3658 |
| 301 | while ((d->state & Running) && d->internal_isResultReadyAt(waitIndex) == false) evaluated: (d->state & Running)| yes Evaluation Count:3904 | yes Evaluation Count:370 |
evaluated: d->internal_isResultReadyAt(waitIndex) == false| yes Evaluation Count:530 | yes Evaluation Count:3374 |
| 370-3904 |
| 302 | d->waitCondition.wait(&d->m_mutex); executed: d->waitCondition.wait(&d->m_mutex);Execution Count:530 | 530 |
| 303 | | - |
| 304 | d->m_exceptionStore.throwPossibleException(); executed (the execution status of this line is deduced): d->m_exceptionStore.throwPossibleException(); | - |
| 305 | } executed: }Execution Count:3744 | 3744 |
| 306 | | - |
| 307 | void QFutureInterfaceBase::waitForFinished() | - |
| 308 | { | - |
| 309 | QMutexLocker lock(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker lock(&d->m_mutex); | - |
| 310 | const bool alreadyFinished = !(d->state & Running); executed (the execution status of this line is deduced): const bool alreadyFinished = !(d->state & Running); | - |
| 311 | lock.unlock(); executed (the execution status of this line is deduced): lock.unlock(); | - |
| 312 | | - |
| 313 | if (!alreadyFinished) { evaluated: !alreadyFinished| yes Evaluation Count:302294 | yes Evaluation Count:1551 |
| 1551-302294 |
| 314 | QThreadPool::globalInstance()->d_func()->stealRunnable(d->runnable); executed (the execution status of this line is deduced): QThreadPool::globalInstance()->d_func()->stealRunnable(d->runnable); | - |
| 315 | | - |
| 316 | lock.relock(); executed (the execution status of this line is deduced): lock.relock(); | - |
| 317 | | - |
| 318 | while (d->state & Running) evaluated: d->state & Running| yes Evaluation Count:40439 | yes Evaluation Count:302101 |
| 40439-302101 |
| 319 | d->waitCondition.wait(&d->m_mutex); executed: d->waitCondition.wait(&d->m_mutex);Execution Count:40439 | 40439 |
| 320 | } executed: }Execution Count:301999 | 301999 |
| 321 | | - |
| 322 | d->m_exceptionStore.throwPossibleException(); executed (the execution status of this line is deduced): d->m_exceptionStore.throwPossibleException(); | - |
| 323 | } executed: }Execution Count:303338 | 303338 |
| 324 | | - |
| 325 | void QFutureInterfaceBase::reportResultsReady(int beginIndex, int endIndex) | - |
| 326 | { | - |
| 327 | if ((d->state & Canceled) || (d->state & Finished) || beginIndex == endIndex) partially evaluated: (d->state & Canceled)| no Evaluation Count:0 | yes Evaluation Count:263547 |
partially evaluated: (d->state & Finished)| no Evaluation Count:0 | yes Evaluation Count:263832 |
evaluated: beginIndex == endIndex| yes Evaluation Count:564 | yes Evaluation Count:263446 |
| 0-263832 |
| 328 | return; executed: return;Execution Count:564 | 564 |
| 329 | | - |
| 330 | d->waitCondition.wakeAll(); executed (the execution status of this line is deduced): d->waitCondition.wakeAll(); | - |
| 331 | | - |
| 332 | if (d->manualProgress == false) { evaluated: d->manualProgress == false| yes Evaluation Count:261386 | yes Evaluation Count:1918 |
| 1918-261386 |
| 333 | if (d->internal_updateProgress(d->m_progressValue + endIndex - beginIndex) == false) { evaluated: d->internal_updateProgress(d->m_progressValue + endIndex - beginIndex) == false| yes Evaluation Count:1131 | yes Evaluation Count:259799 |
| 1131-259799 |
| 334 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, | - |
| 335 | beginIndex, executed (the execution status of this line is deduced): beginIndex, | - |
| 336 | endIndex)); executed (the execution status of this line is deduced): endIndex)); | - |
| 337 | return; executed: return;Execution Count:1131 | 1131 |
| 338 | } | - |
| 339 | | - |
| 340 | d->sendCallOuts(QFutureCallOutEvent(QFutureCallOutEvent::Progress, executed (the execution status of this line is deduced): d->sendCallOuts(QFutureCallOutEvent(QFutureCallOutEvent::Progress, | - |
| 341 | d->m_progressValue, executed (the execution status of this line is deduced): d->m_progressValue, | - |
| 342 | d->m_progressText), executed (the execution status of this line is deduced): d->m_progressText), | - |
| 343 | QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, executed (the execution status of this line is deduced): QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, | - |
| 344 | beginIndex, executed (the execution status of this line is deduced): beginIndex, | - |
| 345 | endIndex)); executed (the execution status of this line is deduced): endIndex)); | - |
| 346 | return; executed: return;Execution Count:258869 | 258869 |
| 347 | } | - |
| 348 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, beginIndex, endIndex)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, beginIndex, endIndex)); | - |
| 349 | } executed: }Execution Count:1918 | 1918 |
| 350 | | - |
| 351 | void QFutureInterfaceBase::setRunnable(QRunnable *runnable) | - |
| 352 | { | - |
| 353 | d->runnable = runnable; executed (the execution status of this line is deduced): d->runnable = runnable; | - |
| 354 | } executed: }Execution Count:523066 | 523066 |
| 355 | | - |
| 356 | void QFutureInterfaceBase::setFilterMode(bool enable) | - |
| 357 | { | - |
| 358 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 359 | resultStoreBase().setFilterMode(enable); executed (the execution status of this line is deduced): resultStoreBase().setFilterMode(enable); | - |
| 360 | } executed: }Execution Count:34 | 34 |
| 361 | | - |
| 362 | void QFutureInterfaceBase::setProgressRange(int minimum, int maximum) | - |
| 363 | { | - |
| 364 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 365 | d->m_progressMinimum = minimum; executed (the execution status of this line is deduced): d->m_progressMinimum = minimum; | - |
| 366 | d->m_progressMaximum = maximum; executed (the execution status of this line is deduced): d->m_progressMaximum = maximum; | - |
| 367 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange, minimum, maximum)); executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange, minimum, maximum)); | - |
| 368 | } executed: }Execution Count:256 | 256 |
| 369 | | - |
| 370 | void QFutureInterfaceBase::setProgressValue(int progressValue) | - |
| 371 | { | - |
| 372 | setProgressValueAndText(progressValue, QString()); executed (the execution status of this line is deduced): setProgressValueAndText(progressValue, QString()); | - |
| 373 | } executed: }Execution Count:123949 | 123949 |
| 374 | | - |
| 375 | void QFutureInterfaceBase::setProgressValueAndText(int progressValue, | - |
| 376 | const QString &progressText) | - |
| 377 | { | - |
| 378 | QMutexLocker locker(&d->m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->m_mutex); | - |
| 379 | if (d->manualProgress == false) evaluated: d->manualProgress == false| yes Evaluation Count:257 | yes Evaluation Count:124162 |
| 257-124162 |
| 380 | d->manualProgress = true; executed: d->manualProgress = true;Execution Count:257 | 257 |
| 381 | if (d->m_progressValue >= progressValue) evaluated: d->m_progressValue >= progressValue| yes Evaluation Count:6621 | yes Evaluation Count:117798 |
| 6621-117798 |
| 382 | return; executed: return;Execution Count:6621 | 6621 |
| 383 | | - |
| 384 | if ((d->state & Canceled) || (d->state & Finished)) partially evaluated: (d->state & Canceled)| no Evaluation Count:0 | yes Evaluation Count:117798 |
partially evaluated: (d->state & Finished)| no Evaluation Count:0 | yes Evaluation Count:117798 |
| 0-117798 |
| 385 | return; | 0 |
| 386 | | - |
| 387 | if (d->internal_updateProgress(progressValue, progressText)) { evaluated: d->internal_updateProgress(progressValue, progressText)| yes Evaluation Count:467 | yes Evaluation Count:117331 |
| 467-117331 |
| 388 | d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Progress, executed (the execution status of this line is deduced): d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Progress, | - |
| 389 | d->m_progressValue, executed (the execution status of this line is deduced): d->m_progressValue, | - |
| 390 | d->m_progressText)); executed (the execution status of this line is deduced): d->m_progressText)); | - |
| 391 | } executed: }Execution Count:467 | 467 |
| 392 | } executed: }Execution Count:117798 | 117798 |
| 393 | | - |
| 394 | QMutex *QFutureInterfaceBase::mutex() const | - |
| 395 | { | - |
| 396 | return &d->m_mutex; executed: return &d->m_mutex;Execution Count:539377 | 539377 |
| 397 | } | - |
| 398 | | - |
| 399 | QtPrivate::ExceptionStore &QFutureInterfaceBase::exceptionStore() | - |
| 400 | { | - |
| 401 | return d->m_exceptionStore; executed: return d->m_exceptionStore;Execution Count:3 | 3 |
| 402 | } | - |
| 403 | | - |
| 404 | QtPrivate::ResultStoreBase &QFutureInterfaceBase::resultStoreBase() | - |
| 405 | { | - |
| 406 | return d->m_results; executed: return d->m_results;Execution Count:523502 | 523502 |
| 407 | } | - |
| 408 | | - |
| 409 | const QtPrivate::ResultStoreBase &QFutureInterfaceBase::resultStoreBase() const | - |
| 410 | { | - |
| 411 | return d->m_results; executed: return d->m_results;Execution Count:278546 | 278546 |
| 412 | } | - |
| 413 | | - |
| 414 | QFutureInterfaceBase &QFutureInterfaceBase::operator=(const QFutureInterfaceBase &other) | - |
| 415 | { | - |
| 416 | other.d->refCount.ref(); executed (the execution status of this line is deduced): other.d->refCount.ref(); | - |
| 417 | if (!d->refCount.deref()) evaluated: !d->refCount.deref()| yes Evaluation Count:59 | yes Evaluation Count:16 |
| 16-59 |
| 418 | delete d; executed: delete d;Execution Count:59 | 59 |
| 419 | d = other.d; executed (the execution status of this line is deduced): d = other.d; | - |
| 420 | return *this; executed: return *this;Execution Count:75 | 75 |
| 421 | } | - |
| 422 | | - |
| 423 | bool QFutureInterfaceBase::refT() const | - |
| 424 | { | - |
| 425 | return d->refCount.refT(); executed: return d->refCount.refT();Execution Count:548189 | 548189 |
| 426 | } | - |
| 427 | | - |
| 428 | bool QFutureInterfaceBase::derefT() const | - |
| 429 | { | - |
| 430 | return d->refCount.derefT(); executed: return d->refCount.derefT();Execution Count:546892 | 546892 |
| 431 | } | - |
| 432 | | - |
| 433 | QFutureInterfaceBasePrivate::QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState) | - |
| 434 | : refCount(1), m_progressValue(0), m_progressMinimum(0), m_progressMaximum(0), | - |
| 435 | state(initialState), pendingResults(0), | - |
| 436 | manualProgress(false), m_expectedResultCount(0), runnable(0) | - |
| 437 | { | - |
| 438 | progressTime.invalidate(); executed (the execution status of this line is deduced): progressTime.invalidate(); | - |
| 439 | } executed: }Execution Count:585142 | 585142 |
| 440 | | - |
| 441 | int QFutureInterfaceBasePrivate::internal_resultCount() const | - |
| 442 | { | - |
| 443 | return m_results.count(); // ### subtract canceled results. executed: return m_results.count();Execution Count:3915 | 3915 |
| 444 | } | - |
| 445 | | - |
| 446 | bool QFutureInterfaceBasePrivate::internal_isResultReadyAt(int index) const | - |
| 447 | { | - |
| 448 | return (m_results.contains(index)); executed: return (m_results.contains(index));Execution Count:18908 | 18908 |
| 449 | } | - |
| 450 | | - |
| 451 | bool QFutureInterfaceBasePrivate::internal_waitForNextResult() | - |
| 452 | { | - |
| 453 | if (m_results.hasNextResult()) never evaluated: m_results.hasNextResult() | 0 |
| 454 | return true; never executed: return true; | 0 |
| 455 | | - |
| 456 | while ((state & QFutureInterfaceBase::Running) && m_results.hasNextResult() == false) never evaluated: (state & QFutureInterfaceBase::Running) never evaluated: m_results.hasNextResult() == false | 0 |
| 457 | waitCondition.wait(&m_mutex); never executed: waitCondition.wait(&m_mutex); | 0 |
| 458 | | - |
| 459 | return (!(state & QFutureInterfaceBase::Canceled) && m_results.hasNextResult()); never executed: return (!(state & QFutureInterfaceBase::Canceled) && m_results.hasNextResult()); | 0 |
| 460 | } | - |
| 461 | | - |
| 462 | bool QFutureInterfaceBasePrivate::internal_updateProgress(int progress, | - |
| 463 | const QString &progressText) | - |
| 464 | { | - |
| 465 | if (m_progressValue >= progress) partially evaluated: m_progressValue >= progress| no Evaluation Count:0 | yes Evaluation Count:379008 |
| 0-379008 |
| 466 | return false; never executed: return false; | 0 |
| 467 | | - |
| 468 | m_progressValue = progress; executed (the execution status of this line is deduced): m_progressValue = progress; | - |
| 469 | m_progressText = progressText; executed (the execution status of this line is deduced): m_progressText = progressText; | - |
| 470 | | - |
| 471 | if (progressTime.isValid() && m_progressValue != m_progressMaximum) // make sure the first and last steps are emitted. evaluated: progressTime.isValid()| yes Evaluation Count:118722 | yes Evaluation Count:259547 |
evaluated: m_progressValue != m_progressMaximum| yes Evaluation Count:118479 | yes Evaluation Count:243 |
| 243-259547 |
| 472 | if (progressTime.elapsed() < (1000 / MaxProgressEmitsPerSecond)) evaluated: progressTime.elapsed() < (1000 / MaxProgressEmitsPerSecond)| yes Evaluation Count:118462 | yes Evaluation Count:17 |
| 17-118462 |
| 473 | return false; executed: return false;Execution Count:118462 | 118462 |
| 474 | | - |
| 475 | progressTime.start(); executed (the execution status of this line is deduced): progressTime.start(); | - |
| 476 | return true; executed: return true;Execution Count:260259 | 260259 |
| 477 | } | - |
| 478 | | - |
| 479 | void QFutureInterfaceBasePrivate::internal_setThrottled(bool enable) | - |
| 480 | { | - |
| 481 | // bail out if we are not changing the state | - |
| 482 | if ((enable && (state & QFutureInterfaceBase::Throttled)) partially evaluated: enable| yes Evaluation Count:1355 | no Evaluation Count:0 |
evaluated: (state & QFutureInterfaceBase::Throttled)| yes Evaluation Count:1352 | yes Evaluation Count:3 |
| 0-1355 |
| 483 | || (!enable && !(state & QFutureInterfaceBase::Throttled))) partially evaluated: !enable| no Evaluation Count:0 | yes Evaluation Count:3 |
never evaluated: !(state & QFutureInterfaceBase::Throttled) | 0-3 |
| 484 | return; executed: return;Execution Count:1352 | 1352 |
| 485 | | - |
| 486 | // change the state | - |
| 487 | if (enable) { partially evaluated: enable| yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
| 488 | state = QFutureInterfaceBase::State(state | QFutureInterfaceBase::Throttled); executed (the execution status of this line is deduced): state = QFutureInterfaceBase::State(state | QFutureInterfaceBase::Throttled); | - |
| 489 | } else { executed: }Execution Count:3 | 3 |
| 490 | state = QFutureInterfaceBase::State(state & ~QFutureInterfaceBase::Throttled); never executed (the execution status of this line is deduced): state = QFutureInterfaceBase::State(state & ~QFutureInterfaceBase::Throttled); | - |
| 491 | if (!(state & QFutureInterfaceBase::Paused)) never evaluated: !(state & QFutureInterfaceBase::Paused) | 0 |
| 492 | pausedWaitCondition.wakeAll(); never executed: pausedWaitCondition.wakeAll(); | 0 |
| 493 | } | 0 |
| 494 | } | - |
| 495 | | - |
| 496 | void QFutureInterfaceBasePrivate::sendCallOut(const QFutureCallOutEvent &callOutEvent) | - |
| 497 | { | - |
| 498 | if (outputConnections.isEmpty()) evaluated: outputConnections.isEmpty()| yes Evaluation Count:1161987 | yes Evaluation Count:1453 |
| 1453-1161987 |
| 499 | return; executed: return;Execution Count:1159645 | 1159645 |
| 500 | | - |
| 501 | for (int i = 0; i < outputConnections.count(); ++i) evaluated: i < outputConnections.count()| yes Evaluation Count:1453 | yes Evaluation Count:1453 |
| 1453 |
| 502 | outputConnections.at(i)->postCallOutEvent(callOutEvent); executed: outputConnections.at(i)->postCallOutEvent(callOutEvent);Execution Count:1453 | 1453 |
| 503 | } executed: }Execution Count:1453 | 1453 |
| 504 | | - |
| 505 | void QFutureInterfaceBasePrivate::sendCallOuts(const QFutureCallOutEvent &callOutEvent1, | - |
| 506 | const QFutureCallOutEvent &callOutEvent2) | - |
| 507 | { | - |
| 508 | if (outputConnections.isEmpty()) evaluated: outputConnections.isEmpty()| yes Evaluation Count:260594 | yes Evaluation Count:6 |
| 6-260594 |
| 509 | return; executed: return;Execution Count:259698 | 259698 |
| 510 | | - |
| 511 | for (int i = 0; i < outputConnections.count(); ++i) { evaluated: i < outputConnections.count()| yes Evaluation Count:6 | yes Evaluation Count:6 |
| 6 |
| 512 | QFutureCallOutInterface *interface = outputConnections.at(i); executed (the execution status of this line is deduced): QFutureCallOutInterface *interface = outputConnections.at(i); | - |
| 513 | interface->postCallOutEvent(callOutEvent1); executed (the execution status of this line is deduced): interface->postCallOutEvent(callOutEvent1); | - |
| 514 | interface->postCallOutEvent(callOutEvent2); executed (the execution status of this line is deduced): interface->postCallOutEvent(callOutEvent2); | - |
| 515 | } executed: }Execution Count:6 | 6 |
| 516 | } executed: }Execution Count:6 | 6 |
| 517 | | - |
| 518 | // This function connects an output interface (for example a QFutureWatcher) | - |
| 519 | // to this future. While holding the lock we check the state and ready results | - |
| 520 | // and add the appropriate callouts to the queue. In order to avoid deadlocks, | - |
| 521 | // the actual callouts are made at the end while not holding the lock. | - |
| 522 | void QFutureInterfaceBasePrivate::connectOutputInterface(QFutureCallOutInterface *interface) | - |
| 523 | { | - |
| 524 | QMutexLocker locker(&m_mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&m_mutex); | - |
| 525 | | - |
| 526 | if (state & QFutureInterfaceBase::Started) { partially evaluated: state & QFutureInterfaceBase::Started| yes Evaluation Count:28 | no Evaluation Count:0 |
| 0-28 |
| 527 | interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Started)); executed (the execution status of this line is deduced): interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Started)); | - |
| 528 | interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange, executed (the execution status of this line is deduced): interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange, | - |
| 529 | m_progressMinimum, executed (the execution status of this line is deduced): m_progressMinimum, | - |
| 530 | m_progressMaximum)); executed (the execution status of this line is deduced): m_progressMaximum)); | - |
| 531 | interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Progress, executed (the execution status of this line is deduced): interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Progress, | - |
| 532 | m_progressValue, executed (the execution status of this line is deduced): m_progressValue, | - |
| 533 | m_progressText)); executed (the execution status of this line is deduced): m_progressText)); | - |
| 534 | } executed: }Execution Count:28 | 28 |
| 535 | | - |
| 536 | QtPrivate::ResultIteratorBase it = m_results.begin(); executed (the execution status of this line is deduced): QtPrivate::ResultIteratorBase it = m_results.begin(); | - |
| 537 | while (it != m_results.end()) { evaluated: it != m_results.end()| yes Evaluation Count:9 | yes Evaluation Count:28 |
| 9-28 |
| 538 | const int begin = it.resultIndex(); executed (the execution status of this line is deduced): const int begin = it.resultIndex(); | - |
| 539 | const int end = begin + it.batchSize(); executed (the execution status of this line is deduced): const int end = begin + it.batchSize(); | - |
| 540 | interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, executed (the execution status of this line is deduced): interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, | - |
| 541 | begin, executed (the execution status of this line is deduced): begin, | - |
| 542 | end)); executed (the execution status of this line is deduced): end)); | - |
| 543 | it.batchedAdvance(); executed (the execution status of this line is deduced): it.batchedAdvance(); | - |
| 544 | } executed: }Execution Count:9 | 9 |
| 545 | | - |
| 546 | if (state & QFutureInterfaceBase::Paused) partially evaluated: state & QFutureInterfaceBase::Paused| no Evaluation Count:0 | yes Evaluation Count:28 |
| 0-28 |
| 547 | interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); never executed: interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); | 0 |
| 548 | | - |
| 549 | if (state & QFutureInterfaceBase::Canceled) evaluated: state & QFutureInterfaceBase::Canceled| yes Evaluation Count:5 | yes Evaluation Count:23 |
| 5-23 |
| 550 | interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); executed: interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Canceled));Execution Count:5 | 5 |
| 551 | | - |
| 552 | if (state & QFutureInterfaceBase::Finished) evaluated: state & QFutureInterfaceBase::Finished| yes Evaluation Count:14 | yes Evaluation Count:14 |
| 14 |
| 553 | interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Finished)); executed: interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Finished));Execution Count:14 | 14 |
| 554 | | - |
| 555 | outputConnections.append(interface); executed (the execution status of this line is deduced): outputConnections.append(interface); | - |
| 556 | } executed: }Execution Count:28 | 28 |
| 557 | | - |
| 558 | void QFutureInterfaceBasePrivate::disconnectOutputInterface(QFutureCallOutInterface *interface) | - |
| 559 | { | - |
| 560 | QMutexLocker lock(&m_mutex); executed (the execution status of this line is deduced): QMutexLocker lock(&m_mutex); | - |
| 561 | const int index = outputConnections.indexOf(interface); executed (the execution status of this line is deduced): const int index = outputConnections.indexOf(interface); | - |
| 562 | if (index == -1) evaluated: index == -1| yes Evaluation Count:22 | yes Evaluation Count:28 |
| 22-28 |
| 563 | return; executed: return;Execution Count:22 | 22 |
| 564 | outputConnections.removeAt(index); executed (the execution status of this line is deduced): outputConnections.removeAt(index); | - |
| 565 | | - |
| 566 | interface->callOutInterfaceDisconnected(); executed (the execution status of this line is deduced): interface->callOutInterfaceDisconnected(); | - |
| 567 | } executed: }Execution Count:28 | 28 |
| 568 | | - |
| 569 | void QFutureInterfaceBasePrivate::setState(QFutureInterfaceBase::State newState) | - |
| 570 | { | - |
| 571 | state = newState; executed (the execution status of this line is deduced): state = newState; | - |
| 572 | } executed: }Execution Count:582985 | 582985 |
| 573 | | - |
| 574 | QT_END_NAMESPACE | - |
| 575 | | - |
| 576 | #endif // QT_NO_QFUTURE | - |
| 577 | | - |
| | |