From 1bac82fa99c4abb33dcf99fa588d72e6cf95d496 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Sep 2021 17:50:02 -0700 Subject: [PATCH] QtTest: fix build with MinGW/GCC 9: no std::mutex support Unfortunately we can't depend on the C++11, 14 or 17 Standard Library, which is not properly and completely implemented everywhere. All Library features above C++98 must be checked with their corresponding __cpp_lib macro before use. This does not apply to the C++17 Core Language. qwaitcondition_p.h:144:20: error: 'mutex' in namespace 'std' does not name a type 144 | using mutex = std::mutex; | ^~~~~ qwaitcondition_p.h:59:1: note: 'std::mutex' is defined in header ''; did you forget to '#include '? 58 | #include +++ |+#include 59 | #include qwaitcondition_p.h:145:33: error: 'condition_variable' in namespace 'std' does not name a type 145 | using condition_variable = std::condition_variable; | ^~~~~~~~~~~~~~~~~~ qwaitcondition_p.h:59:1: note: 'std::condition_variable' is defined in header ''; did you forget to '#include '? 58 | #include +++ |+#include 59 | #include Pick-to: 6.2 Change-Id: I2bbf422288924c198645fffd16a9249e5330136a Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/thread/qwaitcondition_p.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/corelib/thread/qwaitcondition_p.h b/src/corelib/thread/qwaitcondition_p.h index 93ae628143..26a7e03ba7 100644 --- a/src/corelib/thread/qwaitcondition_p.h +++ b/src/corelib/thread/qwaitcondition_p.h @@ -58,12 +58,20 @@ #include #include +// There's no feature macro for C++11 std::mutex, so we use the C++14 one +// for shared_mutex to detect it. +// Needed for: MinGW without gthreads, Integrity +#if __has_include() +# include +#endif + QT_BEGIN_NAMESPACE namespace QtPrivate { -#if defined(Q_OS_INTEGRITY) +#if !defined(__cpp_lib_shared_timed_mutex) +enum class cv_status { no_timeout, timeout }; class condition_variable; class mutex : private QMutex @@ -97,12 +105,12 @@ public: } template - std::cv_status wait_for(std::unique_lock &lock, + cv_status wait_for(std::unique_lock &lock, const std::chrono::duration &d) { return QWaitCondition::wait(lock.mutex(), QDeadlineTimer{d}) - ? std::cv_status::no_timeout - : std::cv_status::timeout; + ? cv_status::no_timeout + : cv_status::timeout; } template bool wait_for(std::unique_lock &lock, @@ -117,12 +125,12 @@ public: } template - std::cv_status wait_until(std::unique_lock &lock, + cv_status wait_until(std::unique_lock &lock, const std::chrono::time_point &t) { return QWaitCondition::wait(lock.mutex(), QDeadlineTimer{t}) - ? std::cv_status::no_timeout - : std::cv_status::timeout; + ? cv_status::no_timeout + : cv_status::timeout; } template @@ -139,12 +147,12 @@ public: }; -#else // Integrity +#else // C++11 threads using mutex = std::mutex; using condition_variable = std::condition_variable; -#endif // Integrity +#endif // C++11 threads } // namespace QtPrivate