QHostInfo: un-QObject-ify QHostInfoLookupManager
QObjects are not even reentrant, but this class must be thread-safe, so it's always ... icky ... to have to analyze a "thread-safe QObject", because for all intents and purposes, that's an oxymoron. The QObject-ness isn't even used, except for defining a private slot, connected to QCoreApplication::destroyed(). That slot just calls waitForDone() on QThreadPool, which is a QObject itself, so use it as the context object for the signal-slot connection, using a lambda as slot. So, strip the class of it's base class, convert the private slot to a lambda and connect to that. Finally, remove the moveToThread() call, because this new class can be destroyed from any thread, not just the main one. Change-Id: I0e33983aa7afd0ad621ece4afd10d9e4adad38c1 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
315ac36e5d
commit
ce86c3373e
@ -907,9 +907,10 @@ void QHostInfoRunnable::run()
|
||||
|
||||
QHostInfoLookupManager::QHostInfoLookupManager() : wasDeleted(false)
|
||||
{
|
||||
moveToThread(QCoreApplicationPrivate::mainThread());
|
||||
#if QT_CONFIG(thread)
|
||||
connect(QCoreApplication::instance(), SIGNAL(destroyed()), SLOT(waitForThreadPoolDone()), Qt::DirectConnection);
|
||||
QObject::connect(QCoreApplication::instance(), &QObject::destroyed,
|
||||
&threadPool, [&](QObject *) { threadPool.waitForDone(); },
|
||||
Qt::DirectConnection);
|
||||
threadPool.setMaxThreadCount(20); // do up to 20 DNS lookups in parallel
|
||||
#endif
|
||||
}
|
||||
|
@ -208,9 +208,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class QHostInfoLookupManager : public QObject
|
||||
class QHostInfoLookupManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QHostInfoLookupManager();
|
||||
~QHostInfoLookupManager();
|
||||
@ -246,11 +245,6 @@ protected:
|
||||
|
||||
private:
|
||||
void rescheduleWithMutexHeld();
|
||||
|
||||
private slots:
|
||||
#if QT_CONFIG(thread)
|
||||
void waitForThreadPoolDone() { threadPool.waitForDone(); }
|
||||
#endif
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user