diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-09-16 12:54:45 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-10-06 05:51:54 +0000 |
commit | cb08b40976150b679d2978f82e3b7ba7c1732780 (patch) | |
tree | 2aee35de3bca6e16ab02f57ecb9576177c93e9dd /src | |
parent | db1027bc360cb86526d95dd0d7f36107a4d36b47 (diff) |
Move detection of <future> to a configure test
<future> is needed by QThread::create. Instead of a fragile series
of preprocessor tests, move its detection to a configure test.
This dramatically simplifies the code, but on the other hand ties
the availability of QThread::create() to the system used to compile
Qt (rather the one used to compile an application).
Change-Id: If1b06363379bf29126cfa68f2a0651cbb78a67f7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/configure.json | 17 | ||||
-rw-r--r-- | src/corelib/thread/qthread.cpp | 4 | ||||
-rw-r--r-- | src/corelib/thread/qthread.h | 36 |
3 files changed, 34 insertions, 23 deletions
diff --git a/src/corelib/configure.json b/src/corelib/configure.json index 3feda2fffc..51e6d1d391 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -251,6 +251,18 @@ ] } }, + "cxx11_future": { + "label": "C++11 <future>", + "type": "compile", + "test": { + "include": "future", + "main": [ + "std::future<int> f = std::async([]() { return 42; });", + "(void)f.get();" + ], + "qmake": "unix:LIBS += -lpthread" + } + }, "cxx11_random": { "label": "C++11 <random>", "type": "compile", @@ -442,6 +454,11 @@ "condition": "features.doubleconversion && libs.doubleconversion", "output": [ "privateFeature" ] }, + "cxx11_future": { + "label": "C++11 <future>", + "condition": "tests.cxx11_future", + "output": [ "publicFeature" ] + }, "cxx11_random": { "label": "C++11 <random>", "condition": "tests.cxx11_random", diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index e3ba1e4449..e92be64dfa 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -925,7 +925,7 @@ bool QThread::isInterruptionRequested() const \sa start() */ -#ifdef QTHREAD_HAS_CREATE +#if QT_CONFIG(cxx11_future) class QThreadCreateThread : public QThread { public: @@ -947,7 +947,7 @@ QThread *QThread::createThreadImpl(std::future<void> &&future) { return new QThreadCreateThread(std::move(future)); } -#endif // QTHREAD_HAS_CREATE +#endif // QT_CONFIG(cxx11_future) /*! \class QDaemonThread diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index 670197d375..03b5424bb6 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -42,17 +43,10 @@ #include <QtCore/qobject.h> -// The implementation of QThread::create uses various C++14/C++17 facilities; -// we must check for their presence. Specifically for glibcxx bundled in MinGW -// with win32 threads, we check the condition found in its <future> header -// since _GLIBCXX_HAS_GTHREADS might then not be defined. -// For std::async (used in all codepaths) -// there is no SG10 feature macro; just test for the header presence. -// For the C++17 codepath do some more throughout checks for std::invoke and -// C++14 lambdas availability. -#if QT_HAS_INCLUDE(<future>) \ - && (!defined(__GLIBCXX__) || (defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1))) -# define QTHREAD_HAS_CREATE +// For QThread::create. The configure-time test just checks for the availability +// of std::future and std::async; for the C++17 codepath we perform some extra +// checks here (for std::invoke and C++14 lambdas). +#if QT_CONFIG(cxx11_future) # include <future> // for std::async # include <functional> // for std::invoke; no guard needed as it's a C++98 header @@ -125,16 +119,16 @@ public: template <typename Function> static QThread *create(Function &&f); #else -#ifdef QTHREAD_HAS_CREATE -#ifdef QTHREAD_HAS_VARIADIC_CREATE +# if QT_CONFIG(cxx11_future) +# ifdef QTHREAD_HAS_VARIADIC_CREATE template <typename Function, typename... Args> static QThread *create(Function &&f, Args &&... args); -#else +# else template <typename Function> static QThread *create(Function &&f); -#endif -#endif -#endif +# endif // QTHREAD_HAS_VARIADIC_CREATE +# endif // QT_CONFIG(cxx11_future) +#endif // Q_QDOC public Q_SLOTS: void start(Priority = InheritPriority); @@ -165,7 +159,7 @@ protected: private: Q_DECLARE_PRIVATE(QThread) -#ifdef QTHREAD_HAS_CREATE +#if QT_CONFIG(cxx11_future) static QThread *createThreadImpl(std::future<void> &&future); #endif @@ -173,9 +167,9 @@ private: friend class QThreadData; }; -#ifdef QTHREAD_HAS_CREATE +#if QT_CONFIG(cxx11_future) -#ifdef QTHREAD_HAS_VARIADIC_CREATE +#if defined(QTHREAD_HAS_VARIADIC_CREATE) // C++17: std::thread's constructor complying call template <typename Function, typename... Args> QThread *QThread::create(Function &&f, Args &&... args) @@ -243,7 +237,7 @@ QThread *QThread::create(Function &&f) } #endif // QTHREAD_HAS_VARIADIC_CREATE -#endif // QTHREAD_HAS_CREATE +#endif // QT_CONFIG(cxx11_future) #else // QT_NO_THREAD |