diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index 3a9fb9d4c8e..9037853feec 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -411,7 +411,7 @@ void QReadWriteLock::unlock() } } -bool QReadWriteLockPrivate::lockForRead(std::unique_lock &lock, QDeadlineTimer timeout) +bool QReadWriteLockPrivate::lockForRead(std::unique_lock &lock, QDeadlineTimer timeout) { Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function @@ -432,7 +432,7 @@ bool QReadWriteLockPrivate::lockForRead(std::unique_lock &lock return true; } -bool QReadWriteLockPrivate::lockForWrite(std::unique_lock &lock, QDeadlineTimer timeout) +bool QReadWriteLockPrivate::lockForWrite(std::unique_lock &lock, QDeadlineTimer timeout) { Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function diff --git a/src/corelib/thread/qreadwritelock_p.h b/src/corelib/thread/qreadwritelock_p.h index 596239e3256..68fa642a735 100644 --- a/src/corelib/thread/qreadwritelock_p.h +++ b/src/corelib/thread/qreadwritelock_p.h @@ -45,10 +45,10 @@ public: explicit QReadWriteLockPrivate(bool isRecursive = false) : recursive(isRecursive) {} - alignas(QtPrivate::IdealMutexAlignment) QtPrivate::condition_variable writerCond; - QtPrivate::condition_variable readerCond; + alignas(QtPrivate::IdealMutexAlignment) std::condition_variable writerCond; + std::condition_variable readerCond; - alignas(QtPrivate::IdealMutexAlignment) QtPrivate::mutex mutex; + alignas(QtPrivate::IdealMutexAlignment) std::mutex mutex; int readerCount = 0; int writerCount = 0; int waitingReaders = 0; @@ -56,8 +56,8 @@ public: const bool recursive; //Called with the mutex locked - bool lockForWrite(std::unique_lock &lock, QDeadlineTimer timeout); - bool lockForRead(std::unique_lock &lock, QDeadlineTimer timeout); + bool lockForWrite(std::unique_lock &lock, QDeadlineTimer timeout); + bool lockForRead(std::unique_lock &lock, QDeadlineTimer timeout); void unlock(); //memory management diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index 4915bde25a9..cc68c2b0cb4 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -255,15 +255,15 @@ namespace { namespace QtSemaphorePrivate { using namespace QtPrivate; struct Layout1 { - alignas(IdealMutexAlignment) QtPrivate::mutex mutex; + alignas(IdealMutexAlignment) std::mutex mutex; qsizetype avail = 0; - alignas(IdealMutexAlignment) QtPrivate::condition_variable cond; + alignas(IdealMutexAlignment) std::condition_variable cond; }; struct Layout2 { - alignas(IdealMutexAlignment) QtPrivate::mutex mutex; - alignas(IdealMutexAlignment) QtPrivate::condition_variable cond; + alignas(IdealMutexAlignment) std::mutex mutex; + alignas(IdealMutexAlignment) std::condition_variable cond; qsizetype avail = 0; }; diff --git a/src/corelib/thread/qwaitcondition_p.h b/src/corelib/thread/qwaitcondition_p.h index f3c931f3922..14833d56eff 100644 --- a/src/corelib/thread/qwaitcondition_p.h +++ b/src/corelib/thread/qwaitcondition_p.h @@ -19,116 +19,18 @@ #include #include -// This header always defines a class called "mutex" and one called -// "condition_variable", so those mustn't be used to mark ELF symbol -// visibility. Don't add more classes to this header! -// ELFVERSION:stop - #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(__cpp_lib_shared_timed_mutex) - -enum class cv_status { no_timeout, timeout }; -class condition_variable; - -class mutex : private QMutex -{ - friend class QtPrivate::condition_variable; - -public: - // all special member functions are ok! - // do not expose the (QMutex::Recursive) ctor - // don't use 'using QMutex::lock;' etc as those have the wrong noexcept - - void lock() { return QMutex::lock(); } - void unlock() { return QMutex::unlock(); } - bool try_lock() { return QMutex::tryLock(); } -}; - -class condition_variable : private QWaitCondition -{ -public: - // all special member functions are ok! - - void notify_one() { QWaitCondition::wakeOne(); } - void notify_all() { QWaitCondition::wakeAll(); } - - void wait(std::unique_lock &lock) { QWaitCondition::wait(lock.mutex()); } - template - void wait(std::unique_lock &lock, Predicate p) - { - while (!p()) - wait(lock); - } - - template - cv_status wait_for(std::unique_lock &lock, - const std::chrono::duration &d) - { - return QWaitCondition::wait(lock.mutex(), QDeadlineTimer{d}) - ? cv_status::no_timeout - : cv_status::timeout; - } - template - bool wait_for(std::unique_lock &lock, - const std::chrono::duration &d, Predicate p) - { - const auto timer = QDeadlineTimer{d}; - while (!p()) { - if (!QWaitCondition::wait(lock.mutex(), timer)) - return p(); - } - return true; - } - - template - cv_status wait_until(std::unique_lock &lock, - const std::chrono::time_point &t) - { - return QWaitCondition::wait(lock.mutex(), QDeadlineTimer{t}) - ? cv_status::no_timeout - : cv_status::timeout; - } - - template - bool wait_until(std::unique_lock &lock, - const std::chrono::time_point &t, Predicate p) - { - const auto timer = QDeadlineTimer{t}; - while (!p()) { - if (!QWaitCondition::wait(lock.mutex(), timer)) - return p(); - } - return true; - } - -}; - -#else // C++11 threads - -using mutex = std::mutex; -using condition_variable = std::condition_variable; - -#endif // C++11 threads - // Ideal alignment for mutex and condition_variable: it's the hardware // interference size (size of a cache line) if the types are likely to contain // the actual data structures, otherwise just that of a pointer. static constexpr quintptr IdealMutexAlignment = - sizeof(QtPrivate::mutex) > sizeof(void *) && - sizeof(QtPrivate::condition_variable) > sizeof(void *) ? + sizeof(std::mutex) > sizeof(void *) && + sizeof(std::condition_variable) > sizeof(void *) ? 64 : alignof(void*); } // namespace QtPrivate diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index fa0042f59f8..9b382089493 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1231,7 +1231,7 @@ class WatchDog : public QThread static constexpr Expectation combine(Expectation e, size_t gen) noexcept { return Expectation{e | (gen << GenerationShift)}; } - bool waitFor(std::unique_lock &m, Expectation e) + bool waitFor(std::unique_lock &m, Expectation e) { auto expectationChanged = [this, e] { return expecting.load(std::memory_order_relaxed) != e; }; switch (state(e)) { @@ -1310,8 +1310,8 @@ public: } private: - QtPrivate::mutex mutex; - QtPrivate::condition_variable waitCondition; + std::mutex mutex; + std::condition_variable waitCondition; std::atomic expecting; };