diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-09-29 01:00:09 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-09-29 01:00:10 +0200 |
commit | 0e1866017fd389629629b150ce252820592506cd (patch) | |
tree | 681142ae0e610ef7af2a43ca2d62c3ea5ed5f91a /src/network/kernel | |
parent | 9567a34bc0d9be87d3b0d6cbcb841837ca1d5659 (diff) | |
parent | 9a8175a13124e156948914854d2fda7436065b08 (diff) |
Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: I6083c3e61b7dbe188f83676f7e7bb268e5ccf2f3
Diffstat (limited to 'src/network/kernel')
-rw-r--r-- | src/network/kernel/qdnslookup.cpp | 7 | ||||
-rw-r--r-- | src/network/kernel/qdnslookup_p.h | 4 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 19 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_p.h | 9 |
4 files changed, 36 insertions, 3 deletions
diff --git a/src/network/kernel/qdnslookup.cpp b/src/network/kernel/qdnslookup.cpp index 10ff35b72c..1b66829070 100644 --- a/src/network/kernel/qdnslookup.cpp +++ b/src/network/kernel/qdnslookup.cpp @@ -49,7 +49,9 @@ QT_BEGIN_NAMESPACE +#if QT_CONFIG(thread) Q_GLOBAL_STATIC(QDnsLookupThreadPool, theDnsLookupThreadPool); +#endif static bool qt_qdnsmailexchangerecord_less_than(const QDnsMailExchangeRecord &r1, const QDnsMailExchangeRecord &r2) { @@ -503,7 +505,9 @@ void QDnsLookup::lookup() connect(d->runnable, SIGNAL(finished(QDnsLookupReply)), this, SLOT(_q_lookupFinished(QDnsLookupReply)), Qt::BlockingQueuedConnection); +#if QT_CONFIG(thread) theDnsLookupThreadPool()->start(d->runnable); +#endif } /*! @@ -1016,6 +1020,7 @@ void QDnsLookupRunnable::run() emit finished(reply); } +#if QT_CONFIG(thread) QDnsLookupThreadPool::QDnsLookupThreadPool() : signalsConnected(false) { @@ -1051,7 +1056,7 @@ void QDnsLookupThreadPool::_q_applicationDestroyed() waitForDone(); signalsConnected = false; } - +#endif // QT_CONFIG(thread) QT_END_NAMESPACE #include "moc_qdnslookup.cpp" diff --git a/src/network/kernel/qdnslookup_p.h b/src/network/kernel/qdnslookup_p.h index 4584396efe..2dc98e527a 100644 --- a/src/network/kernel/qdnslookup_p.h +++ b/src/network/kernel/qdnslookup_p.h @@ -55,7 +55,9 @@ #include "QtCore/qmutex.h" #include "QtCore/qrunnable.h" #include "QtCore/qsharedpointer.h" +#if QT_CONFIG(thread) #include "QtCore/qthreadpool.h" +#endif #include "QtNetwork/qdnslookup.h" #include "QtNetwork/qhostaddress.h" #include "private/qobject_p.h" @@ -132,6 +134,7 @@ private: QHostAddress nameserver; }; +#if QT_CONFIG(thread) class QDnsLookupThreadPool : public QThreadPool { Q_OBJECT @@ -147,6 +150,7 @@ private: QMutex signalsMutex; bool signalsConnected; }; +#endif // QT_CONFIG(thread) class QDnsRecordPrivate : public QSharedData { diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index 4682070712..0973d0dd52 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -704,6 +704,7 @@ void QHostInfoRunnable::run() hostInfo.setLookupId(id); resultEmitter.emitResultsReady(hostInfo); +#if QT_CONFIG(thread) // now also iterate through the postponed ones { QMutexLocker locker(&manager->mutex); @@ -720,6 +721,7 @@ void QHostInfoRunnable::run() manager->postponedLookups.erase(partitionBegin, partitionEnd); } +#endif manager->lookupFinished(this); // thread goes back to QThreadPool @@ -728,8 +730,10 @@ void QHostInfoRunnable::run() QHostInfoLookupManager::QHostInfoLookupManager() : mutex(QMutex::Recursive), wasDeleted(false) { moveToThread(QCoreApplicationPrivate::mainThread()); +#if QT_CONFIG(thread) connect(QCoreApplication::instance(), SIGNAL(destroyed()), SLOT(waitForThreadPoolDone()), Qt::DirectConnection); threadPool.setMaxThreadCount(20); // do up to 20 DNS lookups in parallel +#endif } QHostInfoLookupManager::~QHostInfoLookupManager() @@ -744,15 +748,19 @@ void QHostInfoLookupManager::clear() { { QMutexLocker locker(&mutex); - qDeleteAll(postponedLookups); qDeleteAll(scheduledLookups); qDeleteAll(finishedLookups); +#if QT_CONFIG(thread) + qDeleteAll(postponedLookups); postponedLookups.clear(); +#endif scheduledLookups.clear(); finishedLookups.clear(); } +#if QT_CONFIG(thread) threadPool.waitForDone(); +#endif cache.clear(); } @@ -776,6 +784,7 @@ void QHostInfoLookupManager::work() finishedLookups.clear(); } +#if QT_CONFIG(thread) auto isAlreadyRunning = [this](QHostInfoRunnable *lookup) { return any_of(currentLookups.cbegin(), currentLookups.cend(), ToBeLookedUpEquals(lookup->toBeLookedUp)); }; @@ -808,6 +817,10 @@ void QHostInfoLookupManager::work() } scheduledLookups.erase(scheduledLookups.begin(), it); } +#else + if (!scheduledLookups.isEmpty()) + scheduledLookups.takeFirst()->run(); +#endif } // called by QHostInfo @@ -829,6 +842,7 @@ void QHostInfoLookupManager::abortLookup(int id) QMutexLocker locker(&this->mutex); +#if QT_CONFIG(thread) // is postponed? delete and return for (int i = 0; i < postponedLookups.length(); i++) { if (postponedLookups.at(i)->id == id) { @@ -836,6 +850,7 @@ void QHostInfoLookupManager::abortLookup(int id) return; } } +#endif // is scheduled? delete and return for (int i = 0; i < scheduledLookups.length(); i++) { @@ -866,7 +881,9 @@ void QHostInfoLookupManager::lookupFinished(QHostInfoRunnable *r) return; QMutexLocker locker(&this->mutex); +#if QT_CONFIG(thread) currentLookups.removeOne(r); +#endif finishedLookups.append(r); work(); } diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 82cf34719f..8cce302166 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -61,7 +61,9 @@ #include "QtCore/qobject.h" #include "QtCore/qpointer.h" #include "QtCore/qthread.h" +#if QT_CONFIG(thread) #include "QtCore/qthreadpool.h" +#endif #include "QtCore/qrunnable.h" #include "QtCore/qlist.h" #include "QtCore/qqueue.h" @@ -238,20 +240,25 @@ public: friend class QHostInfoRunnable; protected: +#if QT_CONFIG(thread) QList<QHostInfoRunnable*> currentLookups; // in progress QList<QHostInfoRunnable*> postponedLookups; // postponed because in progress for same host +#endif QQueue<QHostInfoRunnable*> scheduledLookups; // not yet started QList<QHostInfoRunnable*> finishedLookups; // recently finished QList<int> abortedLookups; // ids of aborted lookups +#if QT_CONFIG(thread) QThreadPool threadPool; - +#endif QMutex mutex; bool wasDeleted; private slots: +#if QT_CONFIG(thread) void waitForThreadPoolDone() { threadPool.waitForDone(); } +#endif }; QT_END_NAMESPACE |