diff options
author | Liang Qi <liang.qi@qt.io> | 2016-05-12 07:31:50 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-05-12 08:33:08 +0200 |
commit | 990969655c5fb4d03682e96df9b12101f5ee9815 (patch) | |
tree | b8fb5c50285105c8bc5a938fb50f93ff9f24889d /src/corelib/thread | |
parent | a213011a53f12f101d08a04afc8fdacd2d54a232 (diff) | |
parent | e64b2234e829cc47872225debcf80d6c06db18f0 (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
config_help.txt
configure
src/corelib/io/qprocess_wince.cpp
src/plugins/platforms/windows/qwindowstheme.cpp
src/plugins/platforms/xcb/qxcbbackingstore.cpp
tests/auto/corelib/tools/qtimezone/BLACKLIST
tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
Change-Id: I26644d1cb3b78412c8ff285e2a55bea1bd641c01
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qatomic.cpp | 2 | ||||
-rw-r--r-- | src/corelib/thread/qmutex.cpp | 13 | ||||
-rw-r--r-- | src/corelib/thread/qmutex.h | 11 | ||||
-rw-r--r-- | src/corelib/thread/qmutexpool.cpp | 11 | ||||
-rw-r--r-- | src/corelib/thread/qmutexpool_p.h | 5 | ||||
-rw-r--r-- | src/corelib/thread/qthread.cpp | 6 | ||||
-rw-r--r-- | src/corelib/thread/qthread.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qthread_p.h | 1 | ||||
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 33 |
9 files changed, 43 insertions, 41 deletions
diff --git a/src/corelib/thread/qatomic.cpp b/src/corelib/thread/qatomic.cpp index 23e816af64..ccb0ee6923 100644 --- a/src/corelib/thread/qatomic.cpp +++ b/src/corelib/thread/qatomic.cpp @@ -1289,7 +1289,7 @@ /*! \fn T *QAtomicPointer::loadAcquire() const - Atomically loads the value of this QAtomicPointerusing the "Acquire" memory + Atomically loads the value of this QAtomicPointer using the "Acquire" memory ordering. The value is not modified in any way, but note that there's no guarantee that it remains so. diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 8d9fa82a7a..0b14ec31c2 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -282,19 +282,22 @@ void QMutex::unlock() Q_DECL_NOTHROW unlockInternal(); } +bool QBasicMutex::isRecursive() Q_DECL_NOTHROW +{ + return QT_PREPEND_NAMESPACE(isRecursive)(d_ptr.loadAcquire()); +} + /*! - \fn void QMutex::isRecursive() - \since 5.0 + \overload + \since 5.7 Returns \c true if the mutex is recursive - */ -bool QBasicMutex::isRecursive() +bool QBasicMutex::isRecursive() const Q_DECL_NOTHROW { return QT_PREPEND_NAMESPACE(isRecursive)(d_ptr.loadAcquire()); } - /*! \class QMutexLocker \inmodule QtCore diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 57f89aa439..a06bcd99ac 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -75,7 +75,8 @@ public: return fastTryLock(); } - bool isRecursive(); //### Qt6: mark const + bool isRecursive() Q_DECL_NOTHROW; //### Qt6: remove me + bool isRecursive() const Q_DECL_NOTHROW; private: inline bool fastTryLock() Q_DECL_NOTHROW { @@ -104,7 +105,8 @@ private: friend class QMutexData; }; -class Q_CORE_EXPORT QMutex : public QBasicMutex { +class Q_CORE_EXPORT QMutex : public QBasicMutex +{ public: enum RecursionMode { NonRecursive, Recursive }; explicit QMutex(RecursionMode mode = NonRecursive); @@ -114,7 +116,8 @@ public: bool tryLock(int timeout = 0) QT_MUTEX_LOCK_NOEXCEPT; void unlock() Q_DECL_NOTHROW; - using QBasicMutex::isRecursive; + bool isRecursive() const Q_DECL_NOTHROW + { return QBasicMutex::isRecursive(); } private: Q_DISABLE_COPY(QMutex) @@ -187,7 +190,7 @@ public: inline void lock() Q_DECL_NOTHROW {} inline bool tryLock(int timeout = 0) Q_DECL_NOTHROW { Q_UNUSED(timeout); return true; } inline void unlock() Q_DECL_NOTHROW {} - inline bool isRecursive() Q_DECL_NOTHROW { return true; } + inline bool isRecursive() const Q_DECL_NOTHROW { return true; } private: Q_DISABLE_COPY(QMutex) diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp index 90b6989467..522fd5eac2 100644 --- a/src/corelib/thread/qmutexpool.cpp +++ b/src/corelib/thread/qmutexpool.cpp @@ -92,11 +92,10 @@ Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive)) QMutexPool is destructed. */ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size) - : mutexes(size), recursionMode(recursionMode) + : count(size), + mutexes(new QAtomicPointer<QMutex>[size]()), // (): zero-initialize + recursionMode(recursionMode) { - for (int index = 0; index < mutexes.count(); ++index) { - mutexes[index].store(0); - } } /*! @@ -105,8 +104,8 @@ QMutexPool::QMutexPool(QMutex::RecursionMode recursionMode, int size) */ QMutexPool::~QMutexPool() { - for (int index = 0; index < mutexes.count(); ++index) - delete mutexes[index].load(); + qDeleteAll(mutexes, mutexes + count); + delete[] mutexes; } /*! diff --git a/src/corelib/thread/qmutexpool_p.h b/src/corelib/thread/qmutexpool_p.h index 796e65d960..33e9a52cb7 100644 --- a/src/corelib/thread/qmutexpool_p.h +++ b/src/corelib/thread/qmutexpool_p.h @@ -66,7 +66,7 @@ public: ~QMutexPool(); inline QMutex *get(const void *address) { - int index = uint(quintptr(address)) % mutexes.count(); + int index = uint(quintptr(address)) % count; QMutex *m = mutexes[index].load(); if (m) return m; @@ -78,7 +78,8 @@ public: private: QMutex *createMutex(int index); - QVarLengthArray<QAtomicPointer<QMutex>, 131> mutexes; + int count; + QAtomicPointer<QMutex> *mutexes; QMutex::RecursionMode recursionMode; }; diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 8a797772fc..4aac24f454 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -149,16 +149,12 @@ QThreadPrivate::QThreadPrivate(QThreadData *d) exited(false), returnCode(-1), stackSize(0), priority(QThread::InheritPriority), data(d) { -#if defined (Q_OS_UNIX) - thread_id = 0; -#elif defined (Q_OS_WIN) +#if defined (Q_OS_WIN) handle = 0; # ifndef Q_OS_WINRT id = 0; # endif waiters = 0; -#endif -#if defined (Q_OS_WIN) terminationEnabled = true; terminatePending = false; #endif diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index 68ee366277..410f642ca7 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -56,7 +56,7 @@ class Q_CORE_EXPORT QThread : public QObject { Q_OBJECT public: - static Qt::HANDLE currentThreadId() Q_DECL_NOTHROW; + static Qt::HANDLE currentThreadId() Q_DECL_NOTHROW Q_DECL_PURE_FUNCTION; static QThread *currentThread(); static int idealThreadCount() Q_DECL_NOTHROW; static void yieldCurrentThread(); diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index adcd98b609..37eca9c612 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -176,7 +176,6 @@ public: static QThread *threadForId(int id); #ifdef Q_OS_UNIX - pthread_t thread_id; QWaitCondition thread_done; static void *start(void *arg); diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index f456e56a9c..e7a31e0b70 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -110,6 +110,8 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_THREAD +Q_STATIC_ASSERT(sizeof(pthread_t) == sizeof(Qt::HANDLE)); + enum { ThreadPriorityResetFlag = 0x80000000 }; #if defined(Q_OS_LINUX) && defined(__GLIBC__) && (defined(Q_CC_GNU) || defined(Q_CC_INTEL)) && !defined(QT_LINUXBASE) @@ -239,8 +241,6 @@ QThreadData *QThreadData::current(bool createIfNecessary) void QAdoptedThread::init() { - Q_D(QThread); - d->thread_id = pthread_self(); } /* @@ -328,10 +328,11 @@ void *QThreadPrivate::start(void *arg) // sets the name of the current thread. QString objectName = thr->objectName(); + pthread_t thread_id = reinterpret_cast<pthread_t>(data->threadId); if (Q_LIKELY(objectName.isEmpty())) - setCurrentThreadName(thr->d_func()->thread_id, thr->metaObject()->className()); + setCurrentThreadName(thread_id, thr->metaObject()->className()); else - setCurrentThreadName(thr->d_func()->thread_id, objectName.toLocal8Bit()); + setCurrentThreadName(thread_id, objectName.toLocal8Bit()); } #endif @@ -372,7 +373,6 @@ void QThreadPrivate::finish(void *arg) locker.relock(); } - d->thread_id = 0; d->running = false; d->finished = true; d->interruptionRequested = false; @@ -618,15 +618,16 @@ void QThread::start(Priority priority) } int code = - pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this); + pthread_create(reinterpret_cast<pthread_t *>(&d->data->threadId), &attr, + QThreadPrivate::start, this); if (code == EPERM) { // caller does not have permission to set the scheduling // parameters/policy #if defined(QT_HAS_THREAD_PRIORITY_SCHEDULING) pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); #endif - code = - pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this); + code = pthread_create(reinterpret_cast<pthread_t *>(&d->data->threadId), &attr, + QThreadPrivate::start, this); } pthread_attr_destroy(&attr); @@ -636,7 +637,7 @@ void QThread::start(Priority priority) d->running = false; d->finished = false; - d->thread_id = 0; + d->data->threadId = 0; } } @@ -646,10 +647,10 @@ void QThread::terminate() Q_D(QThread); QMutexLocker locker(&d->mutex); - if (!d->thread_id) + if (!d->data->threadId) return; - int code = pthread_cancel(d->thread_id); + int code = pthread_cancel(reinterpret_cast<pthread_t>(d->data->threadId)); if (code) { qWarning("QThread::start: Thread termination error: %s", qPrintable(qt_error_string((code)))); @@ -662,7 +663,7 @@ bool QThread::wait(unsigned long time) Q_D(QThread); QMutexLocker locker(&d->mutex); - if (d->thread_id == pthread_self()) { + if (reinterpret_cast<pthread_t>(d->data->threadId) == pthread_self()) { qWarning("QThread::wait: Thread tried to wait on itself"); return false; } @@ -704,7 +705,7 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority) int sched_policy; sched_param param; - if (pthread_getschedparam(thread_id, &sched_policy, ¶m) != 0) { + if (pthread_getschedparam(reinterpret_cast<pthread_t>(data->threadId), &sched_policy, ¶m) != 0) { // failed to get the scheduling policy, don't bother setting // the priority qWarning("QThread::setPriority: Cannot get scheduler parameters"); @@ -720,15 +721,15 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority) } param.sched_priority = prio; - int status = pthread_setschedparam(thread_id, sched_policy, ¶m); + int status = pthread_setschedparam(reinterpret_cast<pthread_t>(data->threadId), sched_policy, ¶m); # ifdef SCHED_IDLE // were we trying to set to idle priority and failed? if (status == -1 && sched_policy == SCHED_IDLE && errno == EINVAL) { // reset to lowest priority possible - pthread_getschedparam(thread_id, &sched_policy, ¶m); + pthread_getschedparam(reinterpret_cast<pthread_t>(data->threadId), &sched_policy, ¶m); param.sched_priority = sched_get_priority_min(sched_policy); - pthread_setschedparam(thread_id, sched_policy, ¶m); + pthread_setschedparam(reinterpret_cast<pthread_t>(data->threadId), sched_policy, ¶m); } # else Q_UNUSED(status); |