summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2018-08-21 02:32:49 +0200
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2018-08-21 02:32:50 +0200
commit5a03b75c50b2e34552c7ec3e1e15e7b2a0128bf7 (patch)
tree88e05cd6150e0b3cda4e8716668082c655007fb8 /src/corelib/thread
parent0e7724079f1eae283714ae12769d1372b8f85659 (diff)
parent6553921dd537e416da2f4d1441ab6d63059cda60 (diff)
Merge dev into 5.12
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qmutex.cpp4
-rw-r--r--src/corelib/thread/qmutex.h6
-rw-r--r--src/corelib/thread/qmutex_linux.cpp5
-rw-r--r--src/corelib/thread/qmutex_mac.cpp5
-rw-r--r--src/corelib/thread/qmutex_unix.cpp4
-rw-r--r--src/corelib/thread/qmutexpool.cpp4
-rw-r--r--src/corelib/thread/qmutexpool_p.h4
-rw-r--r--src/corelib/thread/qreadwritelock.cpp3
-rw-r--r--src/corelib/thread/qreadwritelock.h6
-rw-r--r--src/corelib/thread/qreadwritelock_p.h4
-rw-r--r--src/corelib/thread/qsemaphore.cpp4
-rw-r--r--src/corelib/thread/qsemaphore.h7
-rw-r--r--src/corelib/thread/qthread.cpp87
-rw-r--r--src/corelib/thread/qthread.h31
-rw-r--r--src/corelib/thread/qthread_p.h11
-rw-r--r--src/corelib/thread/qthread_unix.cpp12
-rw-r--r--src/corelib/thread/qthread_win.cpp12
-rw-r--r--src/corelib/thread/qthreadpool.cpp4
-rw-r--r--src/corelib/thread/qthreadpool.h4
-rw-r--r--src/corelib/thread/qthreadpool_p.h3
-rw-r--r--src/corelib/thread/qthreadstorage.cpp3
-rw-r--r--src/corelib/thread/qthreadstorage.h79
-rw-r--r--src/corelib/thread/qwaitcondition.h5
-rw-r--r--src/corelib/thread/qwaitcondition_unix.cpp4
-rw-r--r--src/corelib/thread/qwaitcondition_win.cpp3
-rw-r--r--src/corelib/thread/thread.pri110
26 files changed, 248 insertions, 176 deletions
diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp
index 63fb6f3efb..3881ac017e 100644
--- a/src/corelib/thread/qmutex.cpp
+++ b/src/corelib/thread/qmutex.cpp
@@ -42,8 +42,6 @@
#include "qplatformdefs.h"
#include "qmutex.h"
#include <qdebug.h>
-
-#ifndef QT_NO_THREAD
#include "qatomic.h"
#include "qelapsedtimer.h"
#include "qthread.h"
@@ -739,5 +737,3 @@ QT_END_NAMESPACE
#else
# include "qmutex_unix.cpp"
#endif
-
-#endif // QT_NO_THREAD
diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h
index 7cda53db5f..837355a602 100644
--- a/src/corelib/thread/qmutex.h
+++ b/src/corelib/thread/qmutex.h
@@ -54,7 +54,7 @@ class tst_QMutex;
QT_BEGIN_NAMESPACE
-#if !defined(QT_NO_THREAD) || defined(Q_CLANG_QDOC)
+#if QT_CONFIG(thread) || defined(Q_CLANG_QDOC)
#ifdef Q_OS_LINUX
# define QT_MUTEX_LOCK_NOEXCEPT Q_DECL_NOTHROW
@@ -250,7 +250,7 @@ private:
quintptr val;
};
-#else // QT_NO_THREAD && !Q_CLANG_QDOC
+#else // !QT_CONFIG(thread) && !Q_CLANG_QDOC
class Q_CORE_EXPORT QMutex
{
@@ -301,7 +301,7 @@ private:
typedef QMutex QBasicMutex;
-#endif // QT_NO_THREAD && !Q_CLANG_QDOC
+#endif // !QT_CONFIG(thread) && !Q_CLANG_QDOC
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp
index d3d97ea108..507e72cb76 100644
--- a/src/corelib/thread/qmutex_linux.cpp
+++ b/src/corelib/thread/qmutex_linux.cpp
@@ -40,8 +40,6 @@
#include "qplatformdefs.h"
#include "qmutex.h"
-
-#ifndef QT_NO_THREAD
#include "qatomic.h"
#include "qmutex_p.h"
#include "qfutex_p.h"
@@ -54,7 +52,6 @@
# define FUTEX_PRIVATE_FLAG 0
#endif
-
QT_BEGIN_NAMESPACE
using namespace QtFutex;
@@ -183,5 +180,3 @@ void QBasicMutex::unlockInternal() Q_DECL_NOTHROW
}
QT_END_NAMESPACE
-
-#endif // QT_NO_THREAD
diff --git a/src/corelib/thread/qmutex_mac.cpp b/src/corelib/thread/qmutex_mac.cpp
index 67498611c9..9a8d9bc750 100644
--- a/src/corelib/thread/qmutex_mac.cpp
+++ b/src/corelib/thread/qmutex_mac.cpp
@@ -39,9 +39,6 @@
#include "qplatformdefs.h"
#include "qmutex.h"
-
-#if !defined(QT_NO_THREAD)
-
#include "qmutex_p.h"
#include <mach/mach.h>
@@ -89,5 +86,3 @@ void QMutexPrivate::wakeUp() Q_DECL_NOTHROW
QT_END_NAMESPACE
-
-#endif //QT_NO_THREAD
diff --git a/src/corelib/thread/qmutex_unix.cpp b/src/corelib/thread/qmutex_unix.cpp
index 91f02ba3ec..3ee24a292c 100644
--- a/src/corelib/thread/qmutex_unix.cpp
+++ b/src/corelib/thread/qmutex_unix.cpp
@@ -42,8 +42,6 @@
#include "qmutex.h"
#include "qstring.h"
#include "qelapsedtimer.h"
-
-#ifndef QT_NO_THREAD
#include "qatomic.h"
#include "qmutex_p.h"
#include <errno.h>
@@ -159,5 +157,3 @@ void QMutexPrivate::wakeUp() Q_DECL_NOTHROW
#endif
QT_END_NAMESPACE
-
-#endif // QT_NO_THREAD
diff --git a/src/corelib/thread/qmutexpool.cpp b/src/corelib/thread/qmutexpool.cpp
index 90b6989467..3f9e8da942 100644
--- a/src/corelib/thread/qmutexpool.cpp
+++ b/src/corelib/thread/qmutexpool.cpp
@@ -40,8 +40,6 @@
#include "qatomic.h"
#include "qmutexpool_p.h"
-#ifndef QT_NO_THREAD
-
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC_WITH_ARGS(QMutexPool, globalMutexPool, (QMutex::Recursive))
@@ -148,5 +146,3 @@ QMutex *QMutexPool::globalInstanceGet(const void *address)
}
QT_END_NAMESPACE
-
-#endif // QT_NO_THREAD
diff --git a/src/corelib/thread/qmutexpool_p.h b/src/corelib/thread/qmutexpool_p.h
index 58d853b0e3..89d006ac29 100644
--- a/src/corelib/thread/qmutexpool_p.h
+++ b/src/corelib/thread/qmutexpool_p.h
@@ -56,7 +56,7 @@
#include "QtCore/qmutex.h"
#include "QtCore/qvarlengtharray.h"
-#ifndef QT_NO_THREAD
+QT_REQUIRE_CONFIG(thread);
QT_BEGIN_NAMESPACE
@@ -85,6 +85,4 @@ private:
QT_END_NAMESPACE
-#endif // QT_NO_THREAD
-
#endif // QMUTEXPOOL_P_H
diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp
index 42befc4b80..21835ff592 100644
--- a/src/corelib/thread/qreadwritelock.cpp
+++ b/src/corelib/thread/qreadwritelock.cpp
@@ -42,7 +42,6 @@
#include "qplatformdefs.h"
#include "qreadwritelock.h"
-#ifndef QT_NO_THREAD
#include "qmutex.h"
#include "qthread.h"
#include "qwaitcondition.h"
@@ -781,5 +780,3 @@ void QReadWriteLockPrivate::release()
*/
QT_END_NAMESPACE
-
-#endif // QT_NO_THREAD
diff --git a/src/corelib/thread/qreadwritelock.h b/src/corelib/thread/qreadwritelock.h
index ecdb98f2f5..65fa76fd6d 100644
--- a/src/corelib/thread/qreadwritelock.h
+++ b/src/corelib/thread/qreadwritelock.h
@@ -45,7 +45,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
class QReadWriteLockPrivate;
@@ -174,7 +174,7 @@ inline QWriteLocker::QWriteLocker(QReadWriteLock *areadWriteLock)
#pragma warning( pop )
#endif
-#else // QT_NO_THREAD
+#else // QT_CONFIG(thread)
class Q_CORE_EXPORT QReadWriteLock
{
@@ -225,7 +225,7 @@ private:
Q_DISABLE_COPY(QWriteLocker)
};
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qreadwritelock_p.h b/src/corelib/thread/qreadwritelock_p.h
index a01d010043..31da2401c0 100644
--- a/src/corelib/thread/qreadwritelock_p.h
+++ b/src/corelib/thread/qreadwritelock_p.h
@@ -56,7 +56,7 @@
#include <QtCore/qhash.h>
#include <QtCore/qwaitcondition.h>
-#ifndef QT_NO_THREAD
+QT_REQUIRE_CONFIG(thread);
QT_BEGIN_NAMESPACE
@@ -99,6 +99,4 @@ public:
QT_END_NAMESPACE
-#endif // QT_NO_THREAD
-
#endif // QREADWRITELOCK_P_H
diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp
index 82d439a728..bb578ff617 100644
--- a/src/corelib/thread/qsemaphore.cpp
+++ b/src/corelib/thread/qsemaphore.cpp
@@ -39,8 +39,6 @@
****************************************************************************/
#include "qsemaphore.h"
-
-#ifndef QT_NO_THREAD
#include "qmutex.h"
#include "qfutex_p.h"
#include "qwaitcondition.h"
@@ -646,5 +644,3 @@ bool QSemaphore::tryAcquire(int n, int timeout)
QT_END_NAMESPACE
-
-#endif // QT_NO_THREAD
diff --git a/src/corelib/thread/qsemaphore.h b/src/corelib/thread/qsemaphore.h
index 2639085e99..b830ff1bfd 100644
--- a/src/corelib/thread/qsemaphore.h
+++ b/src/corelib/thread/qsemaphore.h
@@ -42,10 +42,9 @@
#include <QtCore/qglobal.h>
-QT_BEGIN_NAMESPACE
-
+QT_REQUIRE_CONFIG(thread);
-#ifndef QT_NO_THREAD
+QT_BEGIN_NAMESPACE
class QSemaphorePrivate;
@@ -113,8 +112,6 @@ private:
int m_n;
};
-#endif // QT_NO_THREAD
-
QT_END_NAMESPACE
#endif // QSEMAPHORE_H
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index 472c6f6795..5df0508829 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -103,7 +103,7 @@ QThreadData::~QThreadData()
void QThreadData::ref()
{
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
(void) _ref.ref();
Q_ASSERT(_ref.load() != 0);
#endif
@@ -111,7 +111,7 @@ void QThreadData::ref()
void QThreadData::deref()
{
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
if (!_ref.deref())
delete this;
#endif
@@ -134,7 +134,7 @@ QAdoptedThread::QAdoptedThread(QThreadData *data)
{
// thread should be running and not finished for the lifetime
// of the application (even if QCoreApplication goes away)
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
d_func()->running = true;
d_func()->finished = false;
init();
@@ -148,7 +148,7 @@ QAdoptedThread::~QAdoptedThread()
// fprintf(stderr, "~QAdoptedThread = %p\n", this);
}
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
void QAdoptedThread::run()
{
// this function should never be called
@@ -756,7 +756,7 @@ int QThread::loopLevel() const
return d->data->eventLoops.size();
}
-#else // QT_NO_THREAD
+#else // QT_CONFIG(thread)
QThread::QThread(QObject *parent)
: QObject(*(new QThreadPrivate), parent)
@@ -765,11 +765,80 @@ QThread::QThread(QObject *parent)
d->data->thread = this;
}
+QThread::~QThread()
+{
+
+}
+
+void QThread::run()
+{
+
+}
+
+int QThread::exec()
+{
+ return 0;
+}
+
+void QThread::start(Priority priority)
+{
+ Q_D(QThread);
+ Q_UNUSED(priority);
+ d->running = true;
+}
+
+void QThread::terminate()
+{
+
+}
+
+void QThread::quit()
+{
+
+}
+
+bool QThread::wait(unsigned long time)
+{
+ Q_UNUSED(time);
+ return false;
+}
+
+bool QThread::event(QEvent* event)
+{
+ return QObject::event(event);
+}
+
+Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW
+{
+ return Qt::HANDLE(currentThread());
+}
+
QThread *QThread::currentThread()
{
return QThreadData::current()->thread;
}
+int QThread::idealThreadCount() Q_DECL_NOTHROW
+{
+ return 1;
+}
+
+void QThread::yieldCurrentThread()
+{
+
+}
+
+bool QThread::isFinished() const
+{
+ return false;
+}
+
+bool QThread::isRunning() const
+{
+ Q_D(const QThread);
+ return d->running;
+}
+
// No threads: so we can just use static variables
static QThreadData *data = 0;
@@ -778,7 +847,9 @@ QThreadData *QThreadData::current(bool createIfNecessary)
if (!data && createIfNecessary) {
data = new QThreadData;
data->thread = new QAdoptedThread(data);
+ data->threadId.store(Qt::HANDLE(data->thread));
data->deref();
+ data->isAdopted = true;
if (!QCoreApplicationPrivate::theMainThread)
QCoreApplicationPrivate::theMainThread = data->thread.load();
}
@@ -811,7 +882,7 @@ QThreadPrivate::~QThreadPrivate()
delete data;
}
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
/*!
\since 5.0
@@ -848,7 +919,7 @@ void QThread::setEventDispatcher(QAbstractEventDispatcher *eventDispatcher)
}
}
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
/*!
\reimp
@@ -1013,7 +1084,7 @@ QDaemonThread::~QDaemonThread()
{
}
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h
index 83c3329cc0..b6c5bf47d0 100644
--- a/src/corelib/thread/qthread.h
+++ b/src/corelib/thread/qthread.h
@@ -66,7 +66,6 @@ class QThreadData;
class QThreadPrivate;
class QAbstractEventDispatcher;
-#ifndef QT_NO_THREAD
class Q_CORE_EXPORT QThread : public QObject
{
Q_OBJECT
@@ -239,36 +238,6 @@ QThread *QThread::create(Function &&f)
#endif // QT_CONFIG(cxx11_future)
-#else // QT_NO_THREAD
-
-class Q_CORE_EXPORT QThread : public QObject
-{
-public:
- static Qt::HANDLE currentThreadId() { return Qt::HANDLE(currentThread()); }
- static QThread* currentThread();
-
- static void sleep(unsigned long);
- static void msleep(unsigned long);
- static void usleep(unsigned long);
-
- QAbstractEventDispatcher *eventDispatcher() const;
- void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
-
-protected:
- QThread(QThreadPrivate &dd, QObject *parent = nullptr);
-
-private:
- explicit QThread(QObject *parent = nullptr);
- static QThread *instance;
-
- friend class QCoreApplication;
- friend class QThreadData;
- friend class QAdoptedThread;
- Q_DECLARE_PRIVATE(QThread)
-};
-
-#endif // QT_NO_THREAD
-
QT_END_NAMESPACE
#endif // QTHREAD_H
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 93f245ff6e..64e3f33191 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -57,7 +57,9 @@
#include "QtCore/qthread.h"
#include "QtCore/qmutex.h"
#include "QtCore/qstack.h"
+#if QT_CONFIG(thread)
#include "QtCore/qwaitcondition.h"
+#endif
#include "QtCore/qmap.h"
#include "QtCore/qcoreapplication.h"
#include "private/qobject_p.h"
@@ -141,7 +143,7 @@ private:
using QVector<QPostEvent>::insert;
};
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
class Q_CORE_EXPORT QDaemonThread : public QThread
{
@@ -210,7 +212,7 @@ public:
}
};
-#else // QT_NO_THREAD
+#else // QT_CONFIG(thread)
class QThreadPrivate : public QObjectPrivate
{
@@ -220,6 +222,7 @@ public:
mutable QMutex mutex;
QThreadData *data;
+ bool running = false;
static void setCurrentThread(QThread*) {}
static QThread *threadForId(int) { return QThread::currentThread(); }
@@ -231,7 +234,7 @@ public:
Q_DECLARE_PUBLIC(QThread)
};
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
class QThreadData
{
@@ -327,7 +330,7 @@ public:
void init();
private:
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
void run() override;
#endif
};
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 0b3c7ddf10..329caa02ba 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -103,7 +103,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
Q_STATIC_ASSERT(sizeof(pthread_t) <= sizeof(Qt::HANDLE));
@@ -270,7 +270,7 @@ extern "C" {
typedef void*(*QtThreadCallback)(void*);
}
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *data)
{
@@ -295,7 +295,7 @@ QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *dat
#endif
}
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX))
static void setCurrentThreadName(const char *name)
@@ -513,7 +513,7 @@ void QThread::yieldCurrentThread()
sched_yield();
}
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
static timespec makeTimespec(time_t secs, long nsecs)
{
@@ -538,7 +538,7 @@ void QThread::usleep(unsigned long usecs)
qt_nanosleep(makeTimespec(usecs / 1000 / 1000, usecs % (1000*1000) * 1000));
}
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
#ifdef QT_HAS_THREAD_PRIORITY_SCHEDULING
#if defined(Q_OS_QNX)
@@ -839,7 +839,7 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority)
#endif
}
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index 83bcb7d751..57ae671897 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -63,7 +63,7 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
#ifdef Q_OS_WINRT
inline DWORD qWinRTTlsAlloc() {
@@ -330,7 +330,7 @@ void qt_set_thread_name(HANDLE threadId, LPCSTR threadName)
** QThreadPrivate
*************************************************************************/
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *data)
{
@@ -342,7 +342,7 @@ QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *dat
#endif
}
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(void *arg) Q_DECL_NOEXCEPT
{
@@ -444,7 +444,7 @@ void QThread::yieldCurrentThread()
#endif
}
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
void QThread::sleep(unsigned long secs)
{
@@ -461,7 +461,7 @@ void QThread::usleep(unsigned long usecs)
::Sleep((usecs / 1000) + 1);
}
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
void QThread::start(Priority priority)
{
@@ -699,6 +699,6 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority)
}
}
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index 157cbeaf4d..ea2c611082 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -43,8 +43,6 @@
#include <algorithm>
-#ifndef QT_NO_THREAD
-
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QThreadPool, theInstance)
@@ -730,5 +728,3 @@ void QThreadPool::cancel(QRunnable *runnable)
QT_END_NAMESPACE
#include "moc_qthreadpool.cpp"
-
-#endif
diff --git a/src/corelib/thread/qthreadpool.h b/src/corelib/thread/qthreadpool.h
index 606e192768..cd27b7c08a 100644
--- a/src/corelib/thread/qthreadpool.h
+++ b/src/corelib/thread/qthreadpool.h
@@ -45,7 +45,7 @@
#include <QtCore/qthread.h>
#include <QtCore/qrunnable.h>
-#ifndef QT_NO_THREAD
+QT_REQUIRE_CONFIG(thread);
QT_BEGIN_NAMESPACE
@@ -97,6 +97,4 @@ public:
QT_END_NAMESPACE
-#endif // QT_NO_THREAD
-
#endif
diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h
index d03ba9d77f..0e6a00d243 100644
--- a/src/corelib/thread/qthreadpool_p.h
+++ b/src/corelib/thread/qthreadpool_p.h
@@ -59,7 +59,7 @@
#include "QtCore/qqueue.h"
#include "private/qobject_p.h"
-#ifndef QT_NO_THREAD
+QT_REQUIRE_CONFIG(thread);
QT_BEGIN_NAMESPACE
@@ -184,5 +184,4 @@ public:
QT_END_NAMESPACE
-#endif // QT_NO_THREAD
#endif
diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp
index c0b523a431..8b82118a5c 100644
--- a/src/corelib/thread/qthreadstorage.cpp
+++ b/src/corelib/thread/qthreadstorage.cpp
@@ -39,7 +39,6 @@
#include "qthreadstorage.h"
-#ifndef QT_NO_THREAD
#include "qthread.h"
#include "qthread_p.h"
#include "qmutex.h"
@@ -323,6 +322,4 @@ void QThreadStorageData::finish(void **p)
\sa localData(), hasLocalData()
*/
-#endif // QT_NO_THREAD
-
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qthreadstorage.h b/src/corelib/thread/qthreadstorage.h
index fed41a0760..d556e33c57 100644
--- a/src/corelib/thread/qthreadstorage.h
+++ b/src/corelib/thread/qthreadstorage.h
@@ -42,7 +42,7 @@
#include <QtCore/qglobal.h>
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
QT_BEGIN_NAMESPACE
@@ -152,6 +152,81 @@ public:
QT_END_NAMESPACE
-#endif // QT_NO_THREAD
+#else // !QT_CONFIG(thread)
+
+#include <qscopedpointer.h>
+
+#include <type_traits>
+
+template <typename T, typename U>
+inline bool qThreadStorage_hasLocalData(const QScopedPointer<T, U> &data)
+{
+ return !!data;
+}
+
+template <typename T, typename U>
+inline bool qThreadStorage_hasLocalData(const QScopedPointer<T*, U> &data)
+{
+ return !!data ? *data != nullptr : false;
+}
+
+template <typename T>
+inline void qThreadStorage_deleteLocalData(T *t)
+{
+ delete t;
+}
+
+template <typename T>
+inline void qThreadStorage_deleteLocalData(T **t)
+{
+ delete *t;
+ delete t;
+}
+
+template <class T>
+class QThreadStorage
+{
+private:
+ struct ScopedPointerThreadStorageDeleter
+ {
+ static inline void cleanup(T *t)
+ {
+ if (t == nullptr)
+ return;
+ qThreadStorage_deleteLocalData(t);
+ }
+ };
+ QScopedPointer<T, ScopedPointerThreadStorageDeleter> data;
+
+public:
+ QThreadStorage() = default;
+ ~QThreadStorage() = default;
+ QThreadStorage(const QThreadStorage &rhs) = delete;
+ QThreadStorage &operator=(const QThreadStorage &rhs) = delete;
+
+ inline bool hasLocalData() const
+ {
+ return qThreadStorage_hasLocalData(data);
+ }
+
+ inline T& localData()
+ {
+ if (!data)
+ data.reset(new T());
+ return *data;
+ }
+
+ inline T localData() const
+ {
+ return !!data ? *data : T();
+ }
+
+ inline void setLocalData(T t)
+ {
+ data.reset(new T(t));
+ }
+};
+
+#endif // QT_CONFIG(thread)
#endif // QTHREADSTORAGE_H
diff --git a/src/corelib/thread/qwaitcondition.h b/src/corelib/thread/qwaitcondition.h
index e42efbdfca..11520e4cfe 100644
--- a/src/corelib/thread/qwaitcondition.h
+++ b/src/corelib/thread/qwaitcondition.h
@@ -46,8 +46,7 @@
QT_BEGIN_NAMESPACE
-
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
class QDeadlineTimer;
class QWaitConditionPrivate;
@@ -98,7 +97,7 @@ public:
void wakeAll() {}
};
-#endif // QT_NO_THREAD
+#endif // QT_CONFIG(thread)
QT_END_NAMESPACE
diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp
index 9706be1504..c93328b4bc 100644
--- a/src/corelib/thread/qwaitcondition_unix.cpp
+++ b/src/corelib/thread/qwaitcondition_unix.cpp
@@ -56,8 +56,6 @@
#include <sys/time.h>
#include <time.h>
-#ifndef QT_NO_THREAD
-
QT_BEGIN_NAMESPACE
#ifdef Q_OS_ANDROID
@@ -264,5 +262,3 @@ bool QWaitCondition::wait(QReadWriteLock *readWriteLock, QDeadlineTimer deadline
}
QT_END_NAMESPACE
-
-#endif // QT_NO_THREAD
diff --git a/src/corelib/thread/qwaitcondition_win.cpp b/src/corelib/thread/qwaitcondition_win.cpp
index 61e4c2bcb1..534456a935 100644
--- a/src/corelib/thread/qwaitcondition_win.cpp
+++ b/src/corelib/thread/qwaitcondition_win.cpp
@@ -45,8 +45,6 @@
#include "qlist.h"
#include "qalgorithms.h"
-#ifndef QT_NO_THREAD
-
#define Q_MUTEX_T void*
#include <private/qmutex_p.h>
#include <private/qreadwritelock_p.h>
@@ -247,4 +245,3 @@ void QWaitCondition::wakeAll()
}
QT_END_NAMESPACE
-#endif // QT_NO_THREAD
diff --git a/src/corelib/thread/thread.pri b/src/corelib/thread/thread.pri
index dae72564b4..22f0de0523 100644
--- a/src/corelib/thread/thread.pri
+++ b/src/corelib/thread/thread.pri
@@ -1,38 +1,66 @@
# Qt core thread module
-# public headers
-HEADERS += thread/qmutex.h \
- thread/qrunnable.h \
- thread/qreadwritelock.h \
- thread/qsemaphore.h \
- thread/qthread.h \
- thread/qthreadpool.h \
- thread/qthreadstorage.h \
- thread/qwaitcondition.h \
- thread/qatomic.h \
- thread/qatomic_bootstrap.h \
- thread/qatomic_cxx11.h \
- thread/qbasicatomic.h \
- thread/qgenericatomic.h
+HEADERS += \
+ thread/qmutex.h \
+ thread/qreadwritelock.h \
+ thread/qrunnable.h \
+ thread/qthread.h \
+ thread/qthreadstorage.h \
+ thread/qwaitcondition.h
-# private headers
-HEADERS += thread/qmutex_p.h \
- thread/qmutexpool_p.h \
- thread/qfutex_p.h \
- thread/qorderedmutexlocker_p.h \
- thread/qreadwritelock_p.h \
- thread/qthread_p.h \
- thread/qthreadpool_p.h
+SOURCES += \
+ thread/qrunnable.cpp \
+ thread/qthread.cpp
-SOURCES += thread/qatomic.cpp \
- thread/qmutex.cpp \
- thread/qreadwritelock.cpp \
- thread/qrunnable.cpp \
- thread/qmutexpool.cpp \
- thread/qsemaphore.cpp \
- thread/qthread.cpp \
- thread/qthreadpool.cpp \
- thread/qthreadstorage.cpp
+win32 {
+ HEADERS += thread/qatomic_msvc.h
+
+ SOURCES += thread/qthread_win.cpp
+} else {
+ SOURCES += thread/qthread_unix.cpp
+}
+
+qtConfig(thread) {
+ HEADERS += \
+ thread/qatomic.h \
+ thread/qatomic_bootstrap.h \
+ thread/qatomic_cxx11.h \
+ thread/qbasicatomic.h \
+ thread/qfutex_p.h \
+ thread/qgenericatomic.h \
+ thread/qmutexpool_p.h \
+ thread/qmutex_p.h \
+ thread/qorderedmutexlocker_p.h \
+ thread/qreadwritelock_p.h \
+ thread/qsemaphore.h \
+ thread/qthreadpool.h \
+ thread/qthreadpool_p.h \
+ thread/qthread_p.h
+
+ SOURCES += \
+ thread/qatomic.cpp \
+ thread/qmutex.cpp \
+ thread/qmutexpool.cpp \
+ thread/qreadwritelock.cpp \
+ thread/qsemaphore.cpp \
+ thread/qthreadpool.cpp \
+ thread/qthreadstorage.cpp
+
+ win32 {
+ SOURCES += \
+ thread/qmutex_win.cpp \
+ thread/qwaitcondition_win.cpp
+ } else {
+ darwin {
+ SOURCES += thread/qmutex_mac.cpp
+ } else: linux {
+ SOURCES += thread/qmutex_linux.cpp
+ } else {
+ SOURCES += thread/qmutex_unix.cpp
+ }
+ SOURCES += thread/qwaitcondition_unix.cpp
+ }
+}
qtConfig(future) {
HEADERS += \
@@ -52,24 +80,4 @@ qtConfig(future) {
thread/qresultstore.cpp
}
-win32 {
- HEADERS += thread/qatomic_msvc.h
-
- SOURCES += \
- thread/qmutex_win.cpp \
- thread/qthread_win.cpp \
- thread/qwaitcondition_win.cpp
-} else {
- darwin {
- SOURCES += thread/qmutex_mac.cpp
- } else: linux {
- SOURCES += thread/qmutex_linux.cpp
- } else {
- SOURCES += thread/qmutex_unix.cpp
- }
- SOURCES += \
- thread/qthread_unix.cpp \
- thread/qwaitcondition_unix.cpp
-}
-
qtConfig(std-atomic64): QMAKE_USE += libatomic