| 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 | #include "qthread.h" | - |
| 43 | | - |
| 44 | #include "qplatformdefs.h" | - |
| 45 | | - |
| 46 | #include <private/qcoreapplication_p.h> | - |
| 47 | | - |
| 48 | #if defined(Q_OS_BLACKBERRY) | - |
| 49 | # include <private/qeventdispatcher_blackberry_p.h> | - |
| 50 | #else | - |
| 51 | # if !defined(QT_NO_GLIB) | - |
| 52 | # include "../kernel/qeventdispatcher_glib_p.h" | - |
| 53 | # endif | - |
| 54 | # include <private/qeventdispatcher_unix_p.h> | - |
| 55 | #endif | - |
| 56 | | - |
| 57 | #include "qthreadstorage.h" | - |
| 58 | | - |
| 59 | #include "qthread_p.h" | - |
| 60 | | - |
| 61 | #include "qdebug.h" | - |
| 62 | | - |
| 63 | #include <sched.h> | - |
| 64 | #include <errno.h> | - |
| 65 | | - |
| 66 | #ifdef Q_OS_BSD4 | - |
| 67 | #include <sys/sysctl.h> | - |
| 68 | #endif | - |
| 69 | #ifdef Q_OS_VXWORKS | - |
| 70 | # if (_WRS_VXWORKS_MAJOR > 6) || ((_WRS_VXWORKS_MAJOR == 6) && (_WRS_VXWORKS_MINOR >= 6)) | - |
| 71 | # include <vxCpuLib.h> | - |
| 72 | # include <cpuset.h> | - |
| 73 | # define QT_VXWORKS_HAS_CPUSET | - |
| 74 | # endif | - |
| 75 | #endif | - |
| 76 | | - |
| 77 | #ifdef Q_OS_HPUX | - |
| 78 | #include <sys/pstat.h> | - |
| 79 | #endif | - |
| 80 | | - |
| 81 | #if defined(Q_OS_MAC) | - |
| 82 | # ifdef qDebug | - |
| 83 | # define old_qDebug qDebug | - |
| 84 | # undef qDebug | - |
| 85 | # endif | - |
| 86 | #ifndef Q_OS_IOS | - |
| 87 | # include <CoreServices/CoreServices.h> | - |
| 88 | #endif //Q_OS_IOS | - |
| 89 | | - |
| 90 | # ifdef old_qDebug | - |
| 91 | # undef qDebug | - |
| 92 | # define qDebug QT_NO_QDEBUG_MACRO | - |
| 93 | # undef old_qDebug | - |
| 94 | # endif | - |
| 95 | #endif | - |
| 96 | | - |
| 97 | #if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) | - |
| 98 | #include <sys/prctl.h> | - |
| 99 | #endif | - |
| 100 | | - |
| 101 | #if defined(Q_OS_LINUX) && !defined(SCHED_IDLE) | - |
| 102 | // from linux/sched.h | - |
| 103 | # define SCHED_IDLE 5 | - |
| 104 | #endif | - |
| 105 | | - |
| 106 | #if defined(Q_OS_DARWIN) || !defined(Q_OS_OPENBSD) && defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && (_POSIX_THREAD_PRIORITY_SCHEDULING-0 >= 0) | - |
| 107 | #define QT_HAS_THREAD_PRIORITY_SCHEDULING | - |
| 108 | #endif | - |
| 109 | | - |
| 110 | | - |
| 111 | QT_BEGIN_NAMESPACE | - |
| 112 | | - |
| 113 | #ifndef QT_NO_THREAD | - |
| 114 | | - |
| 115 | enum { ThreadPriorityResetFlag = 0x80000000 }; | - |
| 116 | | - |
| 117 | #if defined(Q_OS_LINUX) && defined(__GLIBC__) && (defined(Q_CC_GNU) || defined(Q_CC_INTEL)) && !defined(QT_LINUXBASE) | - |
| 118 | /* LSB doesn't have __thread, https://lsbbugs.linuxfoundation.org/show_bug.cgi?id=993 */ | - |
| 119 | #define HAVE_TLS | - |
| 120 | #endif | - |
| 121 | #if defined(Q_CC_XLC) || defined (Q_CC_SUN) | - |
| 122 | #define HAVE_TLS | - |
| 123 | #endif | - |
| 124 | | - |
| 125 | #ifdef HAVE_TLS | - |
| 126 | static __thread QThreadData *currentThreadData = 0; | - |
| 127 | #endif | - |
| 128 | | - |
| 129 | static pthread_once_t current_thread_data_once = PTHREAD_ONCE_INIT; | - |
| 130 | static pthread_key_t current_thread_data_key; | - |
| 131 | | - |
| 132 | static void destroy_current_thread_data(void *p) | - |
| 133 | { | - |
| 134 | #if defined(Q_OS_VXWORKS) | - |
| 135 | // Calling setspecific(..., 0) sets the value to 0 for ALL threads. | - |
| 136 | // The 'set to 1' workaround adds a bit of an overhead though, | - |
| 137 | // since this function is called twice now. | - |
| 138 | if (p == (void *)1) | - |
| 139 | return; | - |
| 140 | #endif | - |
| 141 | // POSIX says the value in our key is set to zero before calling | - |
| 142 | // this destructor function, so we need to set it back to the | - |
| 143 | // right value... | - |
| 144 | pthread_setspecific(current_thread_data_key, p); executed (the execution status of this line is deduced): pthread_setspecific(current_thread_data_key, p); | - |
| 145 | QThreadData *data = static_cast<QThreadData *>(p); executed (the execution status of this line is deduced): QThreadData *data = static_cast<QThreadData *>(p); | - |
| 146 | if (data->isAdopted) { evaluated: data->isAdopted| yes Evaluation Count:18 | yes Evaluation Count:1717279 |
| 18-1717279 |
| 147 | QThread *thread = data->thread; executed (the execution status of this line is deduced): QThread *thread = data->thread; | - |
| 148 | Q_ASSERT(thread); executed (the execution status of this line is deduced): qt_noop(); | - |
| 149 | QThreadPrivate *thread_p = static_cast<QThreadPrivate *>(QObjectPrivate::get(thread)); executed (the execution status of this line is deduced): QThreadPrivate *thread_p = static_cast<QThreadPrivate *>(QObjectPrivate::get(thread)); | - |
| 150 | Q_ASSERT(!thread_p->finished); executed (the execution status of this line is deduced): qt_noop(); | - |
| 151 | thread_p->finish(thread); executed (the execution status of this line is deduced): thread_p->finish(thread); | - |
| 152 | } executed: }Execution Count:18 | 18 |
| 153 | data->deref(); executed (the execution status of this line is deduced): data->deref(); | - |
| 154 | | - |
| 155 | // ... but we must reset it to zero before returning so we aren't | - |
| 156 | // called again (POSIX allows implementations to call destructor | - |
| 157 | // functions repeatedly until all values are zero) | - |
| 158 | pthread_setspecific(current_thread_data_key, executed (the execution status of this line is deduced): pthread_setspecific(current_thread_data_key, | - |
| 159 | #if defined(Q_OS_VXWORKS) executed (the execution status of this line is deduced): | - |
| 160 | (void *)1); executed (the execution status of this line is deduced): | - |
| 161 | #else executed (the execution status of this line is deduced): | - |
| 162 | 0); executed (the execution status of this line is deduced): 0); | - |
| 163 | #endif | - |
| 164 | } executed: }Execution Count:1717384 | 1717384 |
| 165 | | - |
| 166 | static void create_current_thread_data_key() | - |
| 167 | { | - |
| 168 | pthread_key_create(¤t_thread_data_key, destroy_current_thread_data); never executed (the execution status of this line is deduced): pthread_key_create(¤t_thread_data_key, destroy_current_thread_data); | - |
| 169 | } | 0 |
| 170 | | - |
| 171 | static void destroy_current_thread_data_key() | - |
| 172 | { | - |
| 173 | pthread_once(¤t_thread_data_once, create_current_thread_data_key); never executed (the execution status of this line is deduced): pthread_once(¤t_thread_data_once, create_current_thread_data_key); | - |
| 174 | pthread_key_delete(current_thread_data_key); never executed (the execution status of this line is deduced): pthread_key_delete(current_thread_data_key); | - |
| 175 | } | 0 |
| 176 | Q_DESTRUCTOR_FUNCTION(destroy_current_thread_data_key) | 0 |
| 177 | | - |
| 178 | | - |
| 179 | // Utility functions for getting, setting and clearing thread specific data. | - |
| 180 | static QThreadData *get_thread_data() | - |
| 181 | { | - |
| 182 | #ifdef HAVE_TLS | - |
| 183 | return currentThreadData; executed: return currentThreadData;Execution Count:18568914 | 18568914 |
| 184 | #else | - |
| 185 | pthread_once(¤t_thread_data_once, create_current_thread_data_key); | - |
| 186 | return reinterpret_cast<QThreadData *>(pthread_getspecific(current_thread_data_key)); | - |
| 187 | #endif | - |
| 188 | } | - |
| 189 | | - |
| 190 | static void set_thread_data(QThreadData *data) | - |
| 191 | { | - |
| 192 | #ifdef HAVE_TLS | - |
| 193 | currentThreadData = data; executed (the execution status of this line is deduced): currentThreadData = data; | - |
| 194 | #endif | - |
| 195 | pthread_once(¤t_thread_data_once, create_current_thread_data_key); executed (the execution status of this line is deduced): pthread_once(¤t_thread_data_once, create_current_thread_data_key); | - |
| 196 | pthread_setspecific(current_thread_data_key, data); executed (the execution status of this line is deduced): pthread_setspecific(current_thread_data_key, data); | - |
| 197 | } executed: }Execution Count:1717404 | 1717404 |
| 198 | | - |
| 199 | static void clear_thread_data() | - |
| 200 | { | - |
| 201 | #ifdef HAVE_TLS | - |
| 202 | currentThreadData = 0; never executed (the execution status of this line is deduced): currentThreadData = 0; | - |
| 203 | #endif | - |
| 204 | pthread_setspecific(current_thread_data_key, 0); never executed (the execution status of this line is deduced): pthread_setspecific(current_thread_data_key, 0); | - |
| 205 | } | 0 |
| 206 | | - |
| 207 | QThreadData *QThreadData::current() | - |
| 208 | { | - |
| 209 | QThreadData *data = get_thread_data(); executed (the execution status of this line is deduced): QThreadData *data = get_thread_data(); | - |
| 210 | if (!data) { evaluated: !data| yes Evaluation Count:18 | yes Evaluation Count:18568978 |
| 18-18568978 |
| 211 | data = new QThreadData; executed (the execution status of this line is deduced): data = new QThreadData; | - |
| 212 | QT_TRY { | - |
| 213 | set_thread_data(data); executed (the execution status of this line is deduced): set_thread_data(data); | - |
| 214 | data->thread = new QAdoptedThread(data); executed (the execution status of this line is deduced): data->thread = new QAdoptedThread(data); | - |
| 215 | } QT_CATCH(...) { executed: }Execution Count:18 | 18 |
| 216 | clear_thread_data(); never executed (the execution status of this line is deduced): clear_thread_data(); | - |
| 217 | data->deref(); never executed (the execution status of this line is deduced): data->deref(); | - |
| 218 | data = 0; never executed (the execution status of this line is deduced): data = 0; | - |
| 219 | QT_RETHROW; | 0 |
| 220 | } | - |
| 221 | data->deref(); executed (the execution status of this line is deduced): data->deref(); | - |
| 222 | data->isAdopted = true; executed (the execution status of this line is deduced): data->isAdopted = true; | - |
| 223 | data->threadId = (Qt::HANDLE)pthread_self(); executed (the execution status of this line is deduced): data->threadId = (Qt::HANDLE)pthread_self(); | - |
| 224 | if (!QCoreApplicationPrivate::theMainThread) partially evaluated: !QCoreApplicationPrivate::theMainThread| no Evaluation Count:0 | yes Evaluation Count:18 |
| 0-18 |
| 225 | QCoreApplicationPrivate::theMainThread = data->thread; never executed: QCoreApplicationPrivate::theMainThread = data->thread; | 0 |
| 226 | } executed: }Execution Count:18 | 18 |
| 227 | return data; executed: return data;Execution Count:18569006 | 18569006 |
| 228 | } | - |
| 229 | | - |
| 230 | | - |
| 231 | void QAdoptedThread::init() | - |
| 232 | { | - |
| 233 | Q_D(QThread); executed (the execution status of this line is deduced): QThreadPrivate * const d = d_func(); | - |
| 234 | d->thread_id = pthread_self(); executed (the execution status of this line is deduced): d->thread_id = pthread_self(); | - |
| 235 | } executed: }Execution Count:18 | 18 |
| 236 | | - |
| 237 | /* | - |
| 238 | QThreadPrivate | - |
| 239 | */ | - |
| 240 | | - |
| 241 | #if defined(Q_C_CALLBACKS) | - |
| 242 | extern "C" { | - |
| 243 | #endif | - |
| 244 | | - |
| 245 | typedef void*(*QtThreadCallback)(void*); | - |
| 246 | | - |
| 247 | #if defined(Q_C_CALLBACKS) | - |
| 248 | } | - |
| 249 | #endif | - |
| 250 | | - |
| 251 | #endif // QT_NO_THREAD | - |
| 252 | | - |
| 253 | void QThreadPrivate::createEventDispatcher(QThreadData *data) | - |
| 254 | { | - |
| 255 | #if defined(Q_OS_BLACKBERRY) | - |
| 256 | data->eventDispatcher = new QEventDispatcherBlackberry; | - |
| 257 | #else | - |
| 258 | #if !defined(QT_NO_GLIB) | - |
| 259 | if (qEnvironmentVariableIsEmpty("QT_NO_GLIB") partially evaluated: qEnvironmentVariableIsEmpty("QT_NO_GLIB")| yes Evaluation Count:1717390 | no Evaluation Count:0 |
| 0-1717390 |
| 260 | && qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB") partially evaluated: qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")| yes Evaluation Count:1717387 | no Evaluation Count:0 |
| 0-1717387 |
| 261 | && QEventDispatcherGlib::versionSupported()) partially evaluated: QEventDispatcherGlib::versionSupported()| yes Evaluation Count:1717383 | no Evaluation Count:0 |
| 0-1717383 |
| 262 | data->eventDispatcher = new QEventDispatcherGlib; executed: data->eventDispatcher = new QEventDispatcherGlib;Execution Count:1717383 | 1717383 |
| 263 | else | - |
| 264 | #endif | - |
| 265 | data->eventDispatcher = new QEventDispatcherUNIX; never executed: data->eventDispatcher = new QEventDispatcherUNIX; | 0 |
| 266 | #endif | - |
| 267 | | - |
| 268 | data->eventDispatcher->startingUp(); executed (the execution status of this line is deduced): data->eventDispatcher->startingUp(); | - |
| 269 | } executed: }Execution Count:1717377 | 1717377 |
| 270 | | - |
| 271 | #ifndef QT_NO_THREAD | - |
| 272 | | - |
| 273 | #if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX)) | - |
| 274 | static void setCurrentThreadName(pthread_t threadId, const char *name) | - |
| 275 | { | - |
| 276 | # if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) | - |
| 277 | Q_UNUSED(threadId); executed (the execution status of this line is deduced): (void)threadId;; | - |
| 278 | prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0); executed (the execution status of this line is deduced): prctl(15, (unsigned long)name, 0, 0, 0); | - |
| 279 | # elif defined(Q_OS_MAC) | - |
| 280 | Q_UNUSED(threadId); | - |
| 281 | pthread_setname_np(name); | - |
| 282 | # elif defined(Q_OS_QNX) | - |
| 283 | pthread_setname_np(threadId, name); | - |
| 284 | # endif | - |
| 285 | } executed: }Execution Count:1717369 | 1717369 |
| 286 | #endif | - |
| 287 | | - |
| 288 | void *QThreadPrivate::start(void *arg) | - |
| 289 | { | - |
| 290 | #if !defined(Q_OS_LINUX_ANDROID) | - |
| 291 | pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); executed (the execution status of this line is deduced): pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, __null); | - |
| 292 | #endif | - |
| 293 | pthread_cleanup_push(QThreadPrivate::finish, arg); executed (the execution status of this line is deduced): do { __pthread_cleanup_class __clframe (QThreadPrivate::finish, arg); | - |
| 294 | | - |
| 295 | QThread *thr = reinterpret_cast<QThread *>(arg); executed (the execution status of this line is deduced): QThread *thr = reinterpret_cast<QThread *>(arg); | - |
| 296 | QThreadData *data = QThreadData::get2(thr); executed (the execution status of this line is deduced): QThreadData *data = QThreadData::get2(thr); | - |
| 297 | | - |
| 298 | // do we need to reset the thread priority? | - |
| 299 | if (int(thr->d_func()->priority) & ThreadPriorityResetFlag) { evaluated: int(thr->d_func()->priority) & ThreadPriorityResetFlag| yes Evaluation Count:3 | yes Evaluation Count:1717391 |
| 3-1717391 |
| 300 | thr->setPriority(QThread::Priority(thr->d_func()->priority & ~ThreadPriorityResetFlag)); executed (the execution status of this line is deduced): thr->setPriority(QThread::Priority(thr->d_func()->priority & ~ThreadPriorityResetFlag)); | - |
| 301 | } executed: }Execution Count:3 | 3 |
| 302 | | - |
| 303 | data->threadId = (Qt::HANDLE)pthread_self(); executed (the execution status of this line is deduced): data->threadId = (Qt::HANDLE)pthread_self(); | - |
| 304 | set_thread_data(data); executed (the execution status of this line is deduced): set_thread_data(data); | - |
| 305 | | - |
| 306 | data->ref(); executed (the execution status of this line is deduced): data->ref(); | - |
| 307 | { | - |
| 308 | QMutexLocker locker(&thr->d_func()->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&thr->d_func()->mutex); | - |
| 309 | data->quitNow = thr->d_func()->exited; executed (the execution status of this line is deduced): data->quitNow = thr->d_func()->exited; | - |
| 310 | } | - |
| 311 | | - |
| 312 | if (data->eventDispatcher) // custom event dispatcher set? evaluated: data->eventDispatcher| yes Evaluation Count:1 | yes Evaluation Count:1717394 |
| 1-1717394 |
| 313 | data->eventDispatcher->startingUp(); executed: data->eventDispatcher->startingUp();Execution Count:1 | 1 |
| 314 | else | - |
| 315 | createEventDispatcher(data); executed: createEventDispatcher(data);Execution Count:1717394 | 1717394 |
| 316 | | - |
| 317 | #if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX)) | - |
| 318 | // sets the name of the current thread. | - |
| 319 | QString objectName = thr->objectName(); executed (the execution status of this line is deduced): QString objectName = thr->objectName(); | - |
| 320 | | - |
| 321 | if (Q_LIKELY(objectName.isEmpty())) evaluated: __builtin_expect(!!(objectName.isEmpty()), true)| yes Evaluation Count:1714468 | yes Evaluation Count:2917 |
| 2917-1714468 |
| 322 | setCurrentThreadName(thr->d_func()->thread_id, thr->metaObject()->className()); executed: setCurrentThreadName(thr->d_func()->thread_id, thr->metaObject()->className());Execution Count:1714468 | 1714468 |
| 323 | else | - |
| 324 | setCurrentThreadName(thr->d_func()->thread_id, objectName.toLocal8Bit()); executed: setCurrentThreadName(thr->d_func()->thread_id, objectName.toLocal8Bit());Execution Count:2917 | 2917 |
| 325 | | - |
| 326 | #endif | - |
| 327 | | - |
| 328 | emit thr->started(QThread::QPrivateSignal()); executed (the execution status of this line is deduced): thr->started(QThread::QPrivateSignal()); | - |
| 329 | #if !defined(Q_OS_LINUX_ANDROID) | - |
| 330 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); executed (the execution status of this line is deduced): pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, __null); | - |
| 331 | pthread_testcancel(); executed (the execution status of this line is deduced): pthread_testcancel(); | - |
| 332 | #endif | - |
| 333 | thr->run(); executed (the execution status of this line is deduced): thr->run(); | - |
| 334 | | - |
| 335 | pthread_cleanup_pop(1); executed: }Execution Count:1717367 partially evaluated: 0| no Evaluation Count:0 | yes Evaluation Count:1717330 |
| 0-1717367 |
| 336 | | - |
| 337 | return 0; executed: return 0;Execution Count:1717327 | 1717327 |
| 338 | } | - |
| 339 | | - |
| 340 | void QThreadPrivate::finish(void *arg) | - |
| 341 | { | - |
| 342 | QThread *thr = reinterpret_cast<QThread *>(arg); executed (the execution status of this line is deduced): QThread *thr = reinterpret_cast<QThread *>(arg); | - |
| 343 | QThreadPrivate *d = thr->d_func(); executed (the execution status of this line is deduced): QThreadPrivate *d = thr->d_func(); | - |
| 344 | | - |
| 345 | QMutexLocker locker(&d->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex); | - |
| 346 | | - |
| 347 | d->isInFinish = true; executed (the execution status of this line is deduced): d->isInFinish = true; | - |
| 348 | d->priority = QThread::InheritPriority; executed (the execution status of this line is deduced): d->priority = QThread::InheritPriority; | - |
| 349 | void *data = &d->data->tls; executed (the execution status of this line is deduced): void *data = &d->data->tls; | - |
| 350 | locker.unlock(); executed (the execution status of this line is deduced): locker.unlock(); | - |
| 351 | emit thr->finished(QThread::QPrivateSignal()); executed (the execution status of this line is deduced): thr->finished(QThread::QPrivateSignal()); | - |
| 352 | QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); executed (the execution status of this line is deduced): QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); | - |
| 353 | QThreadStorageData::finish((void **)data); executed (the execution status of this line is deduced): QThreadStorageData::finish((void **)data); | - |
| 354 | locker.relock(); executed (the execution status of this line is deduced): locker.relock(); | - |
| 355 | | - |
| 356 | QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher; executed (the execution status of this line is deduced): QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher; | - |
| 357 | if (eventDispatcher) { evaluated: eventDispatcher| yes Evaluation Count:1717370 | yes Evaluation Count:16 |
| 16-1717370 |
| 358 | d->data->eventDispatcher = 0; executed (the execution status of this line is deduced): d->data->eventDispatcher = 0; | - |
| 359 | locker.unlock(); executed (the execution status of this line is deduced): locker.unlock(); | - |
| 360 | eventDispatcher->closingDown(); executed (the execution status of this line is deduced): eventDispatcher->closingDown(); | - |
| 361 | delete eventDispatcher; executed (the execution status of this line is deduced): delete eventDispatcher; | - |
| 362 | locker.relock(); executed (the execution status of this line is deduced): locker.relock(); | - |
| 363 | } executed: }Execution Count:1717357 | 1717357 |
| 364 | | - |
| 365 | d->thread_id = 0; executed (the execution status of this line is deduced): d->thread_id = 0; | - |
| 366 | d->running = false; executed (the execution status of this line is deduced): d->running = false; | - |
| 367 | d->finished = true; executed (the execution status of this line is deduced): d->finished = true; | - |
| 368 | | - |
| 369 | d->isInFinish = false; executed (the execution status of this line is deduced): d->isInFinish = false; | - |
| 370 | d->thread_done.wakeAll(); executed (the execution status of this line is deduced): d->thread_done.wakeAll(); | - |
| 371 | } executed: }Execution Count:1717388 | 1717388 |
| 372 | | - |
| 373 | | - |
| 374 | | - |
| 375 | | - |
| 376 | /************************************************************************** | - |
| 377 | ** QThread | - |
| 378 | *************************************************************************/ | - |
| 379 | | - |
| 380 | Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW | - |
| 381 | { | - |
| 382 | // requires a C cast here otherwise we run into trouble on AIX | - |
| 383 | return (Qt::HANDLE)pthread_self(); executed: return (Qt::HANDLE)pthread_self();Execution Count:10366935 | 10366935 |
| 384 | } | - |
| 385 | | - |
| 386 | #if defined(QT_LINUXBASE) && !defined(_SC_NPROCESSORS_ONLN) | - |
| 387 | // LSB doesn't define _SC_NPROCESSORS_ONLN. | - |
| 388 | # define _SC_NPROCESSORS_ONLN 84 | - |
| 389 | #endif | - |
| 390 | | - |
| 391 | int QThread::idealThreadCount() Q_DECL_NOTHROW | - |
| 392 | { | - |
| 393 | int cores = -1; executed (the execution status of this line is deduced): int cores = -1; | - |
| 394 | | - |
| 395 | #if defined(Q_OS_HPUX) | - |
| 396 | // HP-UX | - |
| 397 | struct pst_dynamic psd; | - |
| 398 | if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) == -1) { | - |
| 399 | perror("pstat_getdynamic"); | - |
| 400 | cores = -1; | - |
| 401 | } else { | - |
| 402 | cores = (int)psd.psd_proc_cnt; | - |
| 403 | } | - |
| 404 | #elif defined(Q_OS_BSD4) | - |
| 405 | // FreeBSD, OpenBSD, NetBSD, BSD/OS, Mac OS X | - |
| 406 | size_t len = sizeof(cores); | - |
| 407 | int mib[2]; | - |
| 408 | mib[0] = CTL_HW; | - |
| 409 | mib[1] = HW_NCPU; | - |
| 410 | if (sysctl(mib, 2, &cores, &len, NULL, 0) != 0) { | - |
| 411 | perror("sysctl"); | - |
| 412 | cores = -1; | - |
| 413 | } | - |
| 414 | #elif defined(Q_OS_IRIX) | - |
| 415 | // IRIX | - |
| 416 | cores = (int)sysconf(_SC_NPROC_ONLN); | - |
| 417 | #elif defined(Q_OS_INTEGRITY) | - |
| 418 | // as of aug 2008 Integrity only supports one single core CPU | - |
| 419 | cores = 1; | - |
| 420 | #elif defined(Q_OS_VXWORKS) | - |
| 421 | // VxWorks | - |
| 422 | # if defined(QT_VXWORKS_HAS_CPUSET) | - |
| 423 | cpuset_t cpus = vxCpuEnabledGet(); | - |
| 424 | cores = 0; | - |
| 425 | | - |
| 426 | // 128 cores should be enough for everyone ;) | - |
| 427 | for (int i = 0; i < 128 && !CPUSET_ISZERO(cpus); ++i) { | - |
| 428 | if (CPUSET_ISSET(cpus, i)) { | - |
| 429 | CPUSET_CLR(cpus, i); | - |
| 430 | cores++; | - |
| 431 | } | - |
| 432 | } | - |
| 433 | # else | - |
| 434 | // as of aug 2008 VxWorks < 6.6 only supports one single core CPU | - |
| 435 | cores = 1; | - |
| 436 | # endif | - |
| 437 | #else | - |
| 438 | // the rest: Linux, Solaris, AIX, Tru64 | - |
| 439 | cores = (int)sysconf(_SC_NPROCESSORS_ONLN); executed (the execution status of this line is deduced): cores = (int)sysconf(_SC_NPROCESSORS_ONLN); | - |
| 440 | #endif | - |
| 441 | | - |
| 442 | return cores; executed: return cores;Execution Count:1061 | 1061 |
| 443 | } | - |
| 444 | | - |
| 445 | void QThread::yieldCurrentThread() | - |
| 446 | { | - |
| 447 | sched_yield(); executed (the execution status of this line is deduced): sched_yield(); | - |
| 448 | } executed: }Execution Count:768 | 768 |
| 449 | | - |
| 450 | static timespec makeTimespec(time_t secs, long nsecs) | - |
| 451 | { | - |
| 452 | struct timespec ts; executed (the execution status of this line is deduced): struct timespec ts; | - |
| 453 | ts.tv_sec = secs; executed (the execution status of this line is deduced): ts.tv_sec = secs; | - |
| 454 | ts.tv_nsec = nsecs; executed (the execution status of this line is deduced): ts.tv_nsec = nsecs; | - |
| 455 | return ts; executed: return ts;Execution Count:414348 | 414348 |
| 456 | } | - |
| 457 | | - |
| 458 | void QThread::sleep(unsigned long secs) | - |
| 459 | { | - |
| 460 | qt_nanosleep(makeTimespec(secs, 0)); executed (the execution status of this line is deduced): qt_nanosleep(makeTimespec(secs, 0)); | - |
| 461 | } executed: }Execution Count:2 | 2 |
| 462 | | - |
| 463 | void QThread::msleep(unsigned long msecs) | - |
| 464 | { | - |
| 465 | qt_nanosleep(makeTimespec(msecs / 1000, msecs % 1000 * 1000 * 1000)); executed (the execution status of this line is deduced): qt_nanosleep(makeTimespec(msecs / 1000, msecs % 1000 * 1000 * 1000)); | - |
| 466 | } executed: }Execution Count:341168 | 341168 |
| 467 | | - |
| 468 | void QThread::usleep(unsigned long usecs) | - |
| 469 | { | - |
| 470 | qt_nanosleep(makeTimespec(usecs / 1000 / 1000, usecs % (1000*1000) * 1000)); executed (the execution status of this line is deduced): qt_nanosleep(makeTimespec(usecs / 1000 / 1000, usecs % (1000*1000) * 1000)); | - |
| 471 | } executed: }Execution Count:73042 | 73042 |
| 472 | | - |
| 473 | #ifdef QT_HAS_THREAD_PRIORITY_SCHEDULING | - |
| 474 | // Does some magic and calculate the Unix scheduler priorities | - |
| 475 | // sched_policy is IN/OUT: it must be set to a valid policy before calling this function | - |
| 476 | // sched_priority is OUT only | - |
| 477 | static bool calculateUnixPriority(int priority, int *sched_policy, int *sched_priority) | - |
| 478 | { | - |
| 479 | #ifdef SCHED_IDLE | - |
| 480 | if (priority == QThread::IdlePriority) { evaluated: priority == QThread::IdlePriority| yes Evaluation Count:8 | yes Evaluation Count:334 |
| 8-334 |
| 481 | *sched_policy = SCHED_IDLE; executed (the execution status of this line is deduced): *sched_policy = 5; | - |
| 482 | *sched_priority = 0; executed (the execution status of this line is deduced): *__sched_priority = 0; | - |
| 483 | return true; executed: return true;Execution Count:8 | 8 |
| 484 | } | - |
| 485 | const int lowestPriority = QThread::LowestPriority; executed (the execution status of this line is deduced): const int lowestPriority = QThread::LowestPriority; | - |
| 486 | #else | - |
| 487 | const int lowestPriority = QThread::IdlePriority; | - |
| 488 | #endif | - |
| 489 | const int highestPriority = QThread::TimeCriticalPriority; executed (the execution status of this line is deduced): const int highestPriority = QThread::TimeCriticalPriority; | - |
| 490 | | - |
| 491 | int prio_min = sched_get_priority_min(*sched_policy); executed (the execution status of this line is deduced): int prio_min = sched_get_priority_min(*sched_policy); | - |
| 492 | int prio_max = sched_get_priority_max(*sched_policy); executed (the execution status of this line is deduced): int prio_max = sched_get_priority_max(*sched_policy); | - |
| 493 | if (prio_min == -1 || prio_max == -1) partially evaluated: prio_min == -1| no Evaluation Count:0 | yes Evaluation Count:334 |
partially evaluated: prio_max == -1| no Evaluation Count:0 | yes Evaluation Count:334 |
| 0-334 |
| 494 | return false; never executed: return false; | 0 |
| 495 | | - |
| 496 | int prio; executed (the execution status of this line is deduced): int prio; | - |
| 497 | // crudely scale our priority enum values to the prio_min/prio_max | - |
| 498 | prio = ((priority - lowestPriority) * (prio_max - prio_min) / highestPriority) + prio_min; executed (the execution status of this line is deduced): prio = ((priority - lowestPriority) * (prio_max - prio_min) / highestPriority) + prio_min; | - |
| 499 | prio = qMax(prio_min, qMin(prio_max, prio)); executed (the execution status of this line is deduced): prio = qMax(prio_min, qMin(prio_max, prio)); | - |
| 500 | | - |
| 501 | *sched_priority = prio; executed (the execution status of this line is deduced): *__sched_priority = prio; | - |
| 502 | return true; executed: return true;Execution Count:334 | 334 |
| 503 | } | - |
| 504 | #endif | - |
| 505 | | - |
| 506 | void QThread::start(Priority priority) | - |
| 507 | { | - |
| 508 | Q_D(QThread); executed (the execution status of this line is deduced): QThreadPrivate * const d = d_func(); | - |
| 509 | QMutexLocker locker(&d->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex); | - |
| 510 | | - |
| 511 | if (d->isInFinish) evaluated: d->isInFinish| yes Evaluation Count:567 | yes Evaluation Count:1719322 |
| 567-1719322 |
| 512 | d->thread_done.wait(locker.mutex()); executed: d->thread_done.wait(locker.mutex());Execution Count:567 | 567 |
| 513 | | - |
| 514 | if (d->running) evaluated: d->running| yes Evaluation Count:2493 | yes Evaluation Count:1717396 |
| 2493-1717396 |
| 515 | return; executed: return;Execution Count:2493 | 2493 |
| 516 | | - |
| 517 | d->running = true; executed (the execution status of this line is deduced): d->running = true; | - |
| 518 | d->finished = false; executed (the execution status of this line is deduced): d->finished = false; | - |
| 519 | d->returnCode = 0; executed (the execution status of this line is deduced): d->returnCode = 0; | - |
| 520 | d->exited = false; executed (the execution status of this line is deduced): d->exited = false; | - |
| 521 | | - |
| 522 | pthread_attr_t attr; executed (the execution status of this line is deduced): pthread_attr_t attr; | - |
| 523 | pthread_attr_init(&attr); executed (the execution status of this line is deduced): pthread_attr_init(&attr); | - |
| 524 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); executed (the execution status of this line is deduced): pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | - |
| 525 | | - |
| 526 | d->priority = priority; executed (the execution status of this line is deduced): d->priority = priority; | - |
| 527 | | - |
| 528 | #if defined(QT_HAS_THREAD_PRIORITY_SCHEDULING) | - |
| 529 | switch (priority) { | - |
| 530 | case InheritPriority: | - |
| 531 | { | - |
| 532 | pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); executed (the execution status of this line is deduced): pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); | - |
| 533 | break; executed: break;Execution Count:1717071 | 1717071 |
| 534 | } | - |
| 535 | | - |
| 536 | default: | - |
| 537 | { | - |
| 538 | int sched_policy; executed (the execution status of this line is deduced): int sched_policy; | - |
| 539 | if (pthread_attr_getschedpolicy(&attr, &sched_policy) != 0) { partially evaluated: pthread_attr_getschedpolicy(&attr, &sched_policy) != 0| no Evaluation Count:0 | yes Evaluation Count:325 |
| 0-325 |
| 540 | // failed to get the scheduling policy, don't bother | - |
| 541 | // setting the priority | - |
| 542 | qWarning("QThread::start: Cannot determine default scheduler policy"); never executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 542, __PRETTY_FUNCTION__).warning("QThread::start: Cannot determine default scheduler policy"); | - |
| 543 | break; | 0 |
| 544 | } | - |
| 545 | | - |
| 546 | int prio; executed (the execution status of this line is deduced): int prio; | - |
| 547 | if (!calculateUnixPriority(priority, &sched_policy, &prio)) { partially evaluated: !calculateUnixPriority(priority, &sched_policy, &prio)| no Evaluation Count:0 | yes Evaluation Count:325 |
| 0-325 |
| 548 | // failed to get the scheduling parameters, don't | - |
| 549 | // bother setting the priority | - |
| 550 | qWarning("QThread::start: Cannot determine scheduler priority range"); never executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 550, __PRETTY_FUNCTION__).warning("QThread::start: Cannot determine scheduler priority range"); | - |
| 551 | break; | 0 |
| 552 | } | - |
| 553 | | - |
| 554 | sched_param sp; executed (the execution status of this line is deduced): sched_param sp; | - |
| 555 | sp.sched_priority = prio; executed (the execution status of this line is deduced): sp.__sched_priority = prio; | - |
| 556 | | - |
| 557 | if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != 0 partially evaluated: pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != 0| no Evaluation Count:0 | yes Evaluation Count:325 |
| 0-325 |
| 558 | || pthread_attr_setschedpolicy(&attr, sched_policy) != 0 evaluated: pthread_attr_setschedpolicy(&attr, sched_policy) != 0| yes Evaluation Count:3 | yes Evaluation Count:322 |
| 3-322 |
| 559 | || pthread_attr_setschedparam(&attr, &sp) != 0) { partially evaluated: pthread_attr_setschedparam(&attr, &sp) != 0| no Evaluation Count:0 | yes Evaluation Count:322 |
| 0-322 |
| 560 | // could not set scheduling hints, fallback to inheriting them | - |
| 561 | // we'll try again from inside the thread | - |
| 562 | pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); executed (the execution status of this line is deduced): pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); | - |
| 563 | d->priority = Priority(priority | ThreadPriorityResetFlag); executed (the execution status of this line is deduced): d->priority = Priority(priority | ThreadPriorityResetFlag); | - |
| 564 | } executed: }Execution Count:3 | 3 |
| 565 | break; executed: break;Execution Count:325 | 325 |
| 566 | } | - |
| 567 | } | - |
| 568 | #endif // QT_HAS_THREAD_PRIORITY_SCHEDULING | - |
| 569 | | - |
| 570 | | - |
| 571 | if (d->stackSize > 0) { partially evaluated: d->stackSize > 0| no Evaluation Count:0 | yes Evaluation Count:1717396 |
| 0-1717396 |
| 572 | #if defined(_POSIX_THREAD_ATTR_STACKSIZE) && (_POSIX_THREAD_ATTR_STACKSIZE-0 > 0) | - |
| 573 | int code = pthread_attr_setstacksize(&attr, d->stackSize); never executed (the execution status of this line is deduced): int code = pthread_attr_setstacksize(&attr, d->stackSize); | - |
| 574 | #else | - |
| 575 | int code = ENOSYS; // stack size not supported, automatically fail | - |
| 576 | #endif // _POSIX_THREAD_ATTR_STACKSIZE | - |
| 577 | | - |
| 578 | if (code) { | 0 |
| 579 | qWarning("QThread::start: Thread stack size error: %s", never executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 579, __PRETTY_FUNCTION__).warning("QThread::start: Thread stack size error: %s", | - |
| 580 | qPrintable(qt_error_string(code))); never executed (the execution status of this line is deduced): QString(qt_error_string(code)).toLocal8Bit().constData()); | - |
| 581 | | - |
| 582 | // we failed to set the stacksize, and as the documentation states, | - |
| 583 | // the thread will fail to run... | - |
| 584 | d->running = false; never executed (the execution status of this line is deduced): d->running = false; | - |
| 585 | d->finished = false; never executed (the execution status of this line is deduced): d->finished = false; | - |
| 586 | return; | 0 |
| 587 | } | - |
| 588 | } | 0 |
| 589 | | - |
| 590 | int code = executed (the execution status of this line is deduced): int code = | - |
| 591 | pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this); executed (the execution status of this line is deduced): pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this); | - |
| 592 | if (code == EPERM) { partially evaluated: code == 1| no Evaluation Count:0 | yes Evaluation Count:1717396 |
| 0-1717396 |
| 593 | // caller does not have permission to set the scheduling | - |
| 594 | // parameters/policy | - |
| 595 | #if defined(QT_HAS_THREAD_PRIORITY_SCHEDULING) | - |
| 596 | pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); never executed (the execution status of this line is deduced): pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); | - |
| 597 | #endif | - |
| 598 | code = never executed (the execution status of this line is deduced): code = | - |
| 599 | pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this); never executed (the execution status of this line is deduced): pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this); | - |
| 600 | } | 0 |
| 601 | | - |
| 602 | pthread_attr_destroy(&attr); executed (the execution status of this line is deduced): pthread_attr_destroy(&attr); | - |
| 603 | | - |
| 604 | if (code) { partially evaluated: code| no Evaluation Count:0 | yes Evaluation Count:1717396 |
| 0-1717396 |
| 605 | qWarning("QThread::start: Thread creation error: %s", qPrintable(qt_error_string(code))); never executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 605, __PRETTY_FUNCTION__).warning("QThread::start: Thread creation error: %s", QString(qt_error_string(code)).toLocal8Bit().constData()); | - |
| 606 | | - |
| 607 | d->running = false; never executed (the execution status of this line is deduced): d->running = false; | - |
| 608 | d->finished = false; never executed (the execution status of this line is deduced): d->finished = false; | - |
| 609 | d->thread_id = 0; never executed (the execution status of this line is deduced): d->thread_id = 0; | - |
| 610 | } | 0 |
| 611 | } executed: }Execution Count:1717396 | 1717396 |
| 612 | | - |
| 613 | void QThread::terminate() | - |
| 614 | { | - |
| 615 | #if !defined(Q_OS_LINUX_ANDROID) | - |
| 616 | Q_D(QThread); executed (the execution status of this line is deduced): QThreadPrivate * const d = d_func(); | - |
| 617 | QMutexLocker locker(&d->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex); | - |
| 618 | | - |
| 619 | if (!d->thread_id) partially evaluated: !d->thread_id| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 620 | return; | 0 |
| 621 | | - |
| 622 | int code = pthread_cancel(d->thread_id); executed (the execution status of this line is deduced): int code = pthread_cancel(d->thread_id); | - |
| 623 | if (code) { partially evaluated: code| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 624 | qWarning("QThread::start: Thread termination error: %s", never executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 624, __PRETTY_FUNCTION__).warning("QThread::start: Thread termination error: %s", | - |
| 625 | qPrintable(qt_error_string((code)))); never executed (the execution status of this line is deduced): QString(qt_error_string((code))).toLocal8Bit().constData()); | - |
| 626 | } | 0 |
| 627 | #endif | - |
| 628 | } executed: }Execution Count:2 | 2 |
| 629 | | - |
| 630 | bool QThread::wait(unsigned long time) | - |
| 631 | { | - |
| 632 | Q_D(QThread); executed (the execution status of this line is deduced): QThreadPrivate * const d = d_func(); | - |
| 633 | QMutexLocker locker(&d->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex); | - |
| 634 | | - |
| 635 | if (d->thread_id == pthread_self()) { partially evaluated: d->thread_id == pthread_self()| no Evaluation Count:0 | yes Evaluation Count:1716643 |
| 0-1716643 |
| 636 | qWarning("QThread::wait: Thread tried to wait on itself"); never executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 636, __PRETTY_FUNCTION__).warning("QThread::wait: Thread tried to wait on itself"); | - |
| 637 | return false; never executed: return false; | 0 |
| 638 | } | - |
| 639 | | - |
| 640 | if (d->finished || !d->running) evaluated: d->finished| yes Evaluation Count:4371 | yes Evaluation Count:1712272 |
partially evaluated: !d->running| no Evaluation Count:0 | yes Evaluation Count:1712272 |
| 0-1712272 |
| 641 | return true; executed: return true;Execution Count:4371 | 4371 |
| 642 | | - |
| 643 | while (d->running) { evaluated: d->running| yes Evaluation Count:1712272 | yes Evaluation Count:1712200 |
| 1712200-1712272 |
| 644 | if (!d->thread_done.wait(locker.mutex(), time)) evaluated: !d->thread_done.wait(locker.mutex(), time)| yes Evaluation Count:72 | yes Evaluation Count:1712200 |
| 72-1712200 |
| 645 | return false; executed: return false;Execution Count:72 | 72 |
| 646 | } executed: }Execution Count:1712200 | 1712200 |
| 647 | return true; executed: return true;Execution Count:1712200 | 1712200 |
| 648 | } | - |
| 649 | | - |
| 650 | void QThread::setTerminationEnabled(bool enabled) | - |
| 651 | { | - |
| 652 | QThread *thr = currentThread(); executed (the execution status of this line is deduced): QThread *thr = currentThread(); | - |
| 653 | Q_ASSERT_X(thr != 0, "QThread::setTerminationEnabled()", executed (the execution status of this line is deduced): qt_noop(); | - |
| 654 | "Current thread was not started with QThread."); | - |
| 655 | | - |
| 656 | Q_UNUSED(thr) executed (the execution status of this line is deduced): (void)thr; | - |
| 657 | #if defined(Q_OS_LINUX_ANDROID) | - |
| 658 | Q_UNUSED(enabled); | - |
| 659 | #else | - |
| 660 | pthread_setcancelstate(enabled ? PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE, NULL); executed (the execution status of this line is deduced): pthread_setcancelstate(enabled ? PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE, __null); | - |
| 661 | if (enabled) evaluated: enabled| yes Evaluation Count:2 | yes Evaluation Count:2 |
| 2 |
| 662 | pthread_testcancel(); executed: pthread_testcancel();Execution Count:2 | 2 |
| 663 | #endif | - |
| 664 | } executed: }Execution Count:2 | 2 |
| 665 | | - |
| 666 | void QThread::setPriority(Priority priority) | - |
| 667 | { | - |
| 668 | Q_D(QThread); executed (the execution status of this line is deduced): QThreadPrivate * const d = d_func(); | - |
| 669 | QMutexLocker locker(&d->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex); | - |
| 670 | if (!d->running) { evaluated: !d->running| yes Evaluation Count:14 | yes Evaluation Count:17 |
| 14-17 |
| 671 | qWarning("QThread::setPriority: Cannot set priority, thread is not running"); executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 671, __PRETTY_FUNCTION__).warning("QThread::setPriority: Cannot set priority, thread is not running"); | - |
| 672 | return; executed: return;Execution Count:14 | 14 |
| 673 | } | - |
| 674 | | - |
| 675 | d->priority = priority; executed (the execution status of this line is deduced): d->priority = priority; | - |
| 676 | | - |
| 677 | // copied from start() with a few modifications: | - |
| 678 | | - |
| 679 | #ifdef QT_HAS_THREAD_PRIORITY_SCHEDULING | - |
| 680 | int sched_policy; executed (the execution status of this line is deduced): int sched_policy; | - |
| 681 | sched_param param; executed (the execution status of this line is deduced): sched_param param; | - |
| 682 | | - |
| 683 | if (pthread_getschedparam(d->thread_id, &sched_policy, ¶m) != 0) { partially evaluated: pthread_getschedparam(d->thread_id, &sched_policy, ¶m) != 0| no Evaluation Count:0 | yes Evaluation Count:17 |
| 0-17 |
| 684 | // failed to get the scheduling policy, don't bother setting | - |
| 685 | // the priority | - |
| 686 | qWarning("QThread::setPriority: Cannot get scheduler parameters"); never executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 686, __PRETTY_FUNCTION__).warning("QThread::setPriority: Cannot get scheduler parameters"); | - |
| 687 | return; | 0 |
| 688 | } | - |
| 689 | | - |
| 690 | int prio; executed (the execution status of this line is deduced): int prio; | - |
| 691 | if (!calculateUnixPriority(priority, &sched_policy, &prio)) { partially evaluated: !calculateUnixPriority(priority, &sched_policy, &prio)| no Evaluation Count:0 | yes Evaluation Count:17 |
| 0-17 |
| 692 | // failed to get the scheduling parameters, don't | - |
| 693 | // bother setting the priority | - |
| 694 | qWarning("QThread::setPriority: Cannot determine scheduler priority range"); never executed (the execution status of this line is deduced): QMessageLogger("thread/qthread_unix.cpp", 694, __PRETTY_FUNCTION__).warning("QThread::setPriority: Cannot determine scheduler priority range"); | - |
| 695 | return; | 0 |
| 696 | } | - |
| 697 | | - |
| 698 | param.sched_priority = prio; executed (the execution status of this line is deduced): param.__sched_priority = prio; | - |
| 699 | int status = pthread_setschedparam(d->thread_id, sched_policy, ¶m); executed (the execution status of this line is deduced): int status = pthread_setschedparam(d->thread_id, sched_policy, ¶m); | - |
| 700 | | - |
| 701 | # ifdef SCHED_IDLE | - |
| 702 | // were we trying to set to idle priority and failed? | - |
| 703 | if (status == -1 && sched_policy == SCHED_IDLE && errno == EINVAL) { partially evaluated: status == -1| no Evaluation Count:0 | yes Evaluation Count:17 |
never evaluated: sched_policy == 5 never evaluated: (*__errno_location ()) == 22 | 0-17 |
| 704 | // reset to lowest priority possible | - |
| 705 | pthread_getschedparam(d->thread_id, &sched_policy, ¶m); never executed (the execution status of this line is deduced): pthread_getschedparam(d->thread_id, &sched_policy, ¶m); | - |
| 706 | param.sched_priority = sched_get_priority_min(sched_policy); never executed (the execution status of this line is deduced): param.__sched_priority = sched_get_priority_min(sched_policy); | - |
| 707 | pthread_setschedparam(d->thread_id, sched_policy, ¶m); never executed (the execution status of this line is deduced): pthread_setschedparam(d->thread_id, sched_policy, ¶m); | - |
| 708 | } | 0 |
| 709 | # else | - |
| 710 | Q_UNUSED(status); | - |
| 711 | # endif // SCHED_IDLE | - |
| 712 | #endif | - |
| 713 | } executed: }Execution Count:17 | 17 |
| 714 | | - |
| 715 | #endif // QT_NO_THREAD | - |
| 716 | | - |
| 717 | QT_END_NAMESPACE | - |
| 718 | | - |
| 719 | | - |
| | |