diff options
author | Lorn Potter <lorn.potter@gmail.com> | 2018-08-29 15:18:32 +1000 |
---|---|---|
committer | Lorn Potter <lorn.potter@gmail.com> | 2018-09-28 02:22:21 +0000 |
commit | cd60b787651ac682595fe40f40c8778c518c5517 (patch) | |
tree | 230a517c9db4504dc059d53c61e50e6f8a4a00c8 | |
parent | 9c72ae61aa28c1e26c7ada21b2853273976a093d (diff) |
wasm: enable Network for nothread
Task-number: QTBUG-70208
Change-Id: Ib73ca0d3c0736336bf517ffb968cbdbab4610319
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r-- | configure.json | 1 | ||||
-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 | ||||
-rw-r--r-- | src/network/ssl/qsslcertificate_openssl.cpp | 19 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_openssl_symbols.cpp | 4 |
7 files changed, 58 insertions, 5 deletions
diff --git a/configure.json b/configure.json index 3d78039a9f..85d6a8c31a 100644 --- a/configure.json +++ b/configure.json @@ -1169,7 +1169,6 @@ }, "network": { "label": "Qt Network", - "condition": "features.thread", "output": [ "privateFeature" ] }, "sql": { 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 diff --git a/src/network/ssl/qsslcertificate_openssl.cpp b/src/network/ssl/qsslcertificate_openssl.cpp index e87264c972..fa87cfeaaf 100644 --- a/src/network/ssl/qsslcertificate_openssl.cpp +++ b/src/network/ssl/qsslcertificate_openssl.cpp @@ -44,8 +44,9 @@ #include "qsslkey_p.h" #include "qsslcertificateextension_p.h" +#if QT_CONFIG(thread) #include <QtCore/private/qmutexpool_p.h> - +#endif QT_BEGIN_NAMESPACE // forward declaration @@ -90,7 +91,9 @@ bool QSslCertificate::isSelfSigned() const QByteArray QSslCertificate::version() const { +#if QT_CONFIG(thread) QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); +#endif if (d->versionString.isEmpty() && d->x509) d->versionString = QByteArray::number(qlonglong(q_X509_get_version(d->x509)) + 1); @@ -99,7 +102,9 @@ QByteArray QSslCertificate::version() const QByteArray QSslCertificate::serialNumber() const { +#if QT_CONFIG(thread) QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); +#endif if (d->serialNumberString.isEmpty() && d->x509) { ASN1_INTEGER *serialNumber = q_X509_get_serialNumber(d->x509); QByteArray hexString; @@ -116,7 +121,9 @@ QByteArray QSslCertificate::serialNumber() const QStringList QSslCertificate::issuerInfo(SubjectInfo info) const { +#if QT_CONFIG(thread) QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); +#endif // lazy init if (d->issuerInfo.isEmpty() && d->x509) d->issuerInfo = @@ -127,7 +134,9 @@ QStringList QSslCertificate::issuerInfo(SubjectInfo info) const QStringList QSslCertificate::issuerInfo(const QByteArray &attribute) const { +#if QT_CONFIG(thread) QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); +#endif // lazy init if (d->issuerInfo.isEmpty() && d->x509) d->issuerInfo = @@ -138,7 +147,9 @@ QStringList QSslCertificate::issuerInfo(const QByteArray &attribute) const QStringList QSslCertificate::subjectInfo(SubjectInfo info) const { +#if QT_CONFIG(thread) QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); +#endif // lazy init if (d->subjectInfo.isEmpty() && d->x509) d->subjectInfo = @@ -149,7 +160,9 @@ QStringList QSslCertificate::subjectInfo(SubjectInfo info) const QStringList QSslCertificate::subjectInfo(const QByteArray &attribute) const { +#if QT_CONFIG(thread) QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); +#endif // lazy init if (d->subjectInfo.isEmpty() && d->x509) d->subjectInfo = @@ -160,7 +173,9 @@ QStringList QSslCertificate::subjectInfo(const QByteArray &attribute) const QList<QByteArray> QSslCertificate::subjectInfoAttributes() const { +#if QT_CONFIG(thread) QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); +#endif // lazy init if (d->subjectInfo.isEmpty() && d->x509) d->subjectInfo = @@ -171,7 +186,9 @@ QList<QByteArray> QSslCertificate::subjectInfoAttributes() const QList<QByteArray> QSslCertificate::issuerInfoAttributes() const { +#if QT_CONFIG(thread) QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); +#endif // lazy init if (d->issuerInfo.isEmpty() && d->x509) d->issuerInfo = diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp index 63cb276d54..8af9b5d77e 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols.cpp +++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp @@ -63,7 +63,9 @@ # include <QtCore/qlibrary.h> #endif #include <QtCore/qmutex.h> +#if QT_CONFIG(thread) #include <private/qmutexpool_p.h> +#endif #include <QtCore/qdatetime.h> #if defined(Q_OS_UNIX) #include <QtCore/qdir.h> @@ -903,11 +905,13 @@ bool q_resolveOpenSslSymbols() { static bool symbolsResolved = false; static bool triedToResolveSymbols = false; +#if QT_CONFIG(thread) #if QT_CONFIG(opensslv11) QMutexLocker locker(QMutexPool::globalInstanceGet((void *)&q_OPENSSL_init_ssl)); #else QMutexLocker locker(QMutexPool::globalInstanceGet((void *)&q_SSL_library_init)); #endif +#endif if (symbolsResolved) return true; if (triedToResolveSymbols) |