From 4870282117b43242d9c2cd6fbde8175b2a907b08 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 9 Nov 2017 15:49:26 -0800 Subject: QSemaphore: fix regression when the timeout < 0 The issue was introduced by eaee1209f0ead5be786e81db8aee604ccfea85b0, so it affected only 5.9.2. [ChangeLog][QtCore][QSemaphore] Fixed a regression that would make tryAcquire() not to wait forever if the timeout was a negative value. Note: new code is advised to only use -1 to indicate "forever", as some other functions taking timeout periods do not accept other values. Task-number: QTBUG-64413 Change-Id: I57a1bd6e0c194530b732fffd14f58fce60d5dfc9 Reviewed-by: Lars Knoll --- src/corelib/thread/qsemaphore.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index ce0c1c91df..f63a08774c 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -214,13 +214,15 @@ bool QSemaphore::tryAcquire(int n) bool QSemaphore::tryAcquire(int n, int timeout) { Q_ASSERT_X(n >= 0, "QSemaphore::tryAcquire", "parameter 'n' must be non-negative"); - if (timeout < 0) - return tryAcquire(n); + + // We're documented to accept any negative value as "forever" + // but QDeadlineTimer only accepts -1. + timeout = qMax(timeout, -1); QDeadlineTimer timer(timeout); QMutexLocker locker(&d->mutex); qint64 remainingTime = timer.remainingTime(); - while (n > d->avail && remainingTime > 0) { + while (n > d->avail && remainingTime != 0) { if (!d->cond.wait(locker.mutex(), remainingTime)) return false; remainingTime = timer.remainingTime(); -- cgit v1.2.3 From 3587a25238b5c0a53285f96383ed0af1c05b3153 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 18 Nov 2017 18:21:13 +0100 Subject: QFlags: support enum classes in setFlag() Unary ~ is not defined for enum classes, so we need a cast. Change-Id: I79d495ebcc24ab960da8dae3be08eb307a9de448 Reviewed-by: Thiago Macieira --- src/corelib/global/qflags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index feeb488acd..72b0a689ff 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -150,7 +150,7 @@ public: Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const Q_DECL_NOTHROW { return (i & Int(f)) == Int(f) && (Int(f) != 0 || i == Int(f) ); } Q_DECL_RELAXED_CONSTEXPR inline QFlags &setFlag(Enum f, bool on = true) Q_DECL_NOTHROW { - return on ? (*this |= f) : (*this &= ~f); + return on ? (*this |= f) : (*this &= ~Int(f)); } private: -- cgit v1.2.3 From fa2a653b3b934783065bb3ea264788e9f8bbdc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 14 Apr 2017 15:13:28 +0200 Subject: Initialize QLoggingRegistry rules on first use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows categorized logging before QCoreApplication has been created, which otherwise would silently fail to output anything because the category would never be enabled, despite QT_LOGGING_RULES being set. Change-Id: I1861e5366ea980dff2ffa753b137276c77278eee Reviewed-by: Kai Koehne Reviewed-by: Morten Johan Sørvig --- src/corelib/io/qloggingregistry.cpp | 3 ++- src/corelib/io/qloggingregistry_p.h | 2 +- src/corelib/kernel/qcoreapplication.cpp | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index 0e7eaeea76..1bf61017f6 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -255,6 +255,7 @@ void QLoggingSettingsParser::parseNextLine(QStringRef line) QLoggingRegistry::QLoggingRegistry() : categoryFilter(defaultCategoryFilter) { + initalizeRules(); // Init on first use } static bool qtLoggingDebug() @@ -283,7 +284,7 @@ static QVector loadRulesFromFile(const QString &filePath) Initializes the rules database by loading $QT_LOGGING_CONF, $QT_LOGGING_RULES, and .config/QtProject/qtlogging.ini. */ -void QLoggingRegistry::init() +void QLoggingRegistry::initalizeRules() { QVector er, qr, cr; // get rules from environment diff --git a/src/corelib/io/qloggingregistry_p.h b/src/corelib/io/qloggingregistry_p.h index a68b993cca..a3857d3588 100644 --- a/src/corelib/io/qloggingregistry_p.h +++ b/src/corelib/io/qloggingregistry_p.h @@ -113,7 +113,7 @@ class Q_AUTOTEST_EXPORT QLoggingRegistry public: QLoggingRegistry(); - void init(); + void initalizeRules(); void registerCategory(QLoggingCategory *category, QtMsgType enableForLevel); void unregisterCategory(QLoggingCategory *category); diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index cba279c184..bf423cef21 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -776,8 +776,6 @@ void QCoreApplicationPrivate::init() if (!coreappdata()->applicationVersionSet) coreappdata()->applicationVersion = appVersion(); - QLoggingRegistry::instance()->init(); - #if QT_CONFIG(library) // Reset the lib paths, so that they will be recomputed, taking the availability of argv[0] // into account. If necessary, recompute right away and replay the manual changes on top of the -- cgit v1.2.3