summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-07-17 01:00:27 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2019-07-17 11:47:20 +0200
commiteb9c5fd4f919592d58f35abfdf9907f1b180885c (patch)
tree03b140d076dcbbfdce0256313f49c9bce7d7d8be /src/network/kernel
parent19e45ee4c1007ddb9de4c0be9c4423e75ebe9330 (diff)
parent64df0eda36fea91b71783b23bfdf733b6983c250 (diff)
Merge "Merge remote-tracking branch 'origin/5.13' into dev"
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qhostinfo.cpp34
-rw-r--r--src/network/kernel/qhostinfo_p.h9
2 files changed, 19 insertions, 24 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index 6caee5e097..c17ba38e36 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -891,7 +891,9 @@ QHostInfoLookupManager::QHostInfoLookupManager() : wasDeleted(false)
QHostInfoLookupManager::~QHostInfoLookupManager()
{
+ QMutexLocker locker(&mutex);
wasDeleted = true;
+ locker.unlock();
// don't qDeleteAll currentLookups, the QThreadPool has ownership
clear();
@@ -919,6 +921,8 @@ void QHostInfoLookupManager::clear()
void QHostInfoLookupManager::work()
{
+ QMutexLocker locker(&mutex);
+
if (wasDeleted)
return;
@@ -926,8 +930,6 @@ void QHostInfoLookupManager::work()
// - launch new lookups via the thread pool
// - make sure only one lookup per host/IP is in progress
- QMutexLocker locker(&mutex);
-
if (!finishedLookups.isEmpty()) {
// remove ID from aborted if it is in there
for (int i = 0; i < finishedLookups.length(); i++) {
@@ -979,10 +981,11 @@ void QHostInfoLookupManager::work()
// called by QHostInfo
void QHostInfoLookupManager::scheduleLookup(QHostInfoRunnable *r)
{
+ QMutexLocker locker(&this->mutex);
+
if (wasDeleted)
return;
- QMutexLocker locker(&this->mutex);
scheduledLookups.enqueue(r);
work();
}
@@ -990,11 +993,11 @@ void QHostInfoLookupManager::scheduleLookup(QHostInfoRunnable *r)
// called by QHostInfo
void QHostInfoLookupManager::abortLookup(int id)
{
+ QMutexLocker locker(&this->mutex);
+
if (wasDeleted)
return;
- QMutexLocker locker(&this->mutex);
-
#if QT_CONFIG(thread)
// is postponed? delete and return
for (int i = 0; i < postponedLookups.length(); i++) {
@@ -1020,20 +1023,22 @@ void QHostInfoLookupManager::abortLookup(int id)
// called from QHostInfoRunnable
bool QHostInfoLookupManager::wasAborted(int id)
{
+ QMutexLocker locker(&this->mutex);
+
if (wasDeleted)
return true;
- QMutexLocker locker(&this->mutex);
return abortedLookups.contains(id);
}
// called from QHostInfoRunnable
void QHostInfoLookupManager::lookupFinished(QHostInfoRunnable *r)
{
+ QMutexLocker locker(&this->mutex);
+
if (wasDeleted)
return;
- QMutexLocker locker(&this->mutex);
#if QT_CONFIG(thread)
currentLookups.removeOne(r);
#endif
@@ -1095,23 +1100,10 @@ void qt_qhostinfo_cache_inject(const QString &hostname, const QHostInfo &resolut
QHostInfoCache::QHostInfoCache() : max_age(60), enabled(true), cache(128)
{
#ifdef QT_QHOSTINFO_CACHE_DISABLED_BY_DEFAULT
- enabled = false;
+ enabled.store(false, std::memory_order_relaxed);
#endif
}
-bool QHostInfoCache::isEnabled()
-{
- return enabled;
-}
-
-// this function is currently only used for the auto tests
-// and not usable by public API
-void QHostInfoCache::setEnabled(bool e)
-{
- enabled = e;
-}
-
-
QHostInfo QHostInfoCache::get(const QString &name, bool *valid)
{
QMutexLocker locker(&this->mutex);
diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h
index 7df3f5414c..0433d1d17b 100644
--- a/src/network/kernel/qhostinfo_p.h
+++ b/src/network/kernel/qhostinfo_p.h
@@ -73,6 +73,7 @@
#include <QNetworkSession>
#include <QSharedPointer>
+#include <atomic>
QT_BEGIN_NAMESPACE
@@ -177,10 +178,12 @@ public:
void put(const QString &name, const QHostInfo &info);
void clear();
- bool isEnabled();
- void setEnabled(bool e);
+ bool isEnabled() { return enabled.load(std::memory_order_relaxed); }
+ // this function is currently only used for the auto tests
+ // and not usable by public API
+ void setEnabled(bool e) { enabled.store(e, std::memory_order_relaxed); }
private:
- bool enabled;
+ std::atomic<bool> enabled;
struct QHostInfoCacheElement {
QHostInfo info;
QElapsedTimer age;