From 5f531ae2ac873c09deda096d292777422c4dee4d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 17 May 2023 21:54:56 -0700 Subject: [PATCH] QDeadlineTimer: make the ForeverConstant an enum class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoids the implicit cast to int, which then fixes the overloading problem of QDeadlineTimer with older functions taking an integer with the number of milliseconds. Without this and the workarounds, an expression like waitCondition.wait(&mutex, QDeadlineTimer::Forever); would be the same as waitCondition.wait(&mutex, 0); which is the opposite of "forever". This means we can remove the overloads added earlier this week in commits 37f1fb78eeb107d593f9a7bf0491466a1c60e068 (QMutex), 63704529b75f831ffeb965765c10caf09f7883fe (QReadWriteLock), and 37f1fb78eeb107d593f9a7bf0491466a1c60e068 (QSemaphore). I hadn't thought this solution until noting that QWaitCondition needed the same solution and then remembering how Qt::Uninitialized was fixed of the same problem. Change-Id: I5f7f427ded124479baa6fffd176023ddfb91077d Reviewed-by: Qt CI Bot Reviewed-by: Ahmad Samir Reviewed-by: MÃ¥rten Nordheim --- src/corelib/kernel/qdeadlinetimer.h | 3 ++- src/corelib/thread/qmutex.h | 6 ------ src/corelib/thread/qreadwritelock.h | 9 --------- src/corelib/thread/qsemaphore.h | 5 ----- 4 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index dab5e055ae0..b872422add0 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -23,7 +23,8 @@ QT_BEGIN_NAMESPACE class Q_CORE_EXPORT QDeadlineTimer { public: - enum ForeverConstant { Forever }; + enum class ForeverConstant { Forever }; + static constexpr ForeverConstant Forever = ForeverConstant::Forever; constexpr QDeadlineTimer(Qt::TimerType type_ = Qt::CoarseTimer) noexcept : type(type_) {} diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 8a75db012d3..7a6bd1a3ba7 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -145,12 +145,6 @@ public: return success; } -#ifndef Q_QDOC - // because tryLock(QDeadlineTimer::Forever) is tryLock(0) - bool tryLock(QDeadlineTimer::ForeverConstant) QT_MUTEX_LOCK_NOEXCEPT - { lock(); return true; } -#endif - // TimedLockable concept template bool try_lock_for(std::chrono::duration duration) diff --git a/src/corelib/thread/qreadwritelock.h b/src/corelib/thread/qreadwritelock.h index 352aaab2cf5..a00c0262fa7 100644 --- a/src/corelib/thread/qreadwritelock.h +++ b/src/corelib/thread/qreadwritelock.h @@ -43,15 +43,6 @@ public: void unlock(); -#ifndef Q_QDOC - // because tryLockForXxx(QDeadlineTimer::Forever) is the same - // as tryLockForXxx(0), which is not forever - bool tryLockForRead(QDeadlineTimer::ForeverConstant) - { lockForRead(); return true; } - bool tryLockForWrite(QDeadlineTimer::ForeverConstant) - { lockForWrite(); return true; } -#endif - private: Q_DISABLE_COPY(QReadWriteLock) QAtomicPointer d_ptr; diff --git a/src/corelib/thread/qsemaphore.h b/src/corelib/thread/qsemaphore.h index f20bef42882..0e01f33f36c 100644 --- a/src/corelib/thread/qsemaphore.h +++ b/src/corelib/thread/qsemaphore.h @@ -23,11 +23,6 @@ public: QT_CORE_INLINE_SINCE(6, 6) bool tryAcquire(int n, int timeout); bool tryAcquire(int n, QDeadlineTimer timeout); -#ifndef Q_QDOC - // because tryAcquire(n, QDeadlineTimer::Forever) is tryLock(n, 0) - bool tryAcquire(int n, QDeadlineTimer::ForeverConstant) - { acquire(n); return true; } -#endif #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) template bool tryAcquire(int n, std::chrono::duration timeout)