diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager.cpp | 4 | ||||
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager_p.cpp | 36 | ||||
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager_p.h | 3 |
3 files changed, 27 insertions, 16 deletions
diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 65a15d7..d2c7317 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC_INIT(TYPE, NAME); \ static void NAME##_cleanup() \ { \ - delete this_##NAME.pointer; \ + this_##NAME.pointer->cleanup(); \ this_##NAME.pointer = 0; \ } \ static TYPE *NAME() \ @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE delete x; \ else { \ qAddPostRoutine(NAME##_cleanup); \ - this_##NAME.pointer->updateConfigurations(); \ + this_##NAME.pointer->initialize(); \ } \ } \ return this_##NAME.pointer; \ diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 2391a34..17e47bd 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -66,11 +66,31 @@ QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() qRegisterMetaType<QNetworkConfigurationPrivatePointer>("QNetworkConfigurationPrivatePointer"); } +void QNetworkConfigurationManagerPrivate::initialize() +{ + //Two stage construction, because we only want to do this heavyweight work for the winner of the Q_GLOBAL_STATIC race. + bearerThread = new QThread(); + bearerThread->moveToThread(QCoreApplicationPrivate::mainThread()); // because cleanup() is called in main thread context. + moveToThread(bearerThread); + bearerThread->start(); + updateConfigurations(); +} + QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() { QMutexLocker locker(&mutex); qDeleteAll(sessionEngines); + if (bearerThread) + bearerThread->quit(); +} + +void QNetworkConfigurationManagerPrivate::cleanup() +{ + QThread* thread = bearerThread; + deleteLater(); + if(thread->wait(5000)) + delete thread; } QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() @@ -356,13 +376,6 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (sender()) return; - if (thread() != QCoreApplicationPrivate::mainThread()) { - if (thread() != QThread::currentThread()) - return; - - moveToThread(QCoreApplicationPrivate::mainThread()); - } - updating = false; #ifndef QT_NO_LIBRARY @@ -382,7 +395,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() else sessionEngines.append(engine); - engine->moveToThread(QCoreApplicationPrivate::mainThread()); + engine->moveToThread(bearerThread); connect(engine, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations())); @@ -424,14 +437,9 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (firstUpdate) { firstUpdate = false; QList<QBearerEngine*> enginesToInitialize = sessionEngines; //shallow copy the list in case it is modified when we unlock mutex - Qt::ConnectionType connectionType; - if (QCoreApplicationPrivate::mainThread() == QThread::currentThread()) - connectionType = Qt::DirectConnection; - else - connectionType = Qt::BlockingQueuedConnection; locker.unlock(); foreach (QBearerEngine* engine, enginesToInitialize) { - QMetaObject::invokeMethod(engine, "initialize", connectionType); + QMetaObject::invokeMethod(engine, "initialize", Qt::BlockingQueuedConnection); } } } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 1679c3b..b3c83bc 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -91,6 +91,8 @@ public: void enablePolling(); void disablePolling(); + void initialize(); + void cleanup(); public slots: void updateConfigurations(); @@ -105,6 +107,7 @@ Q_SIGNALS: private: QTimer *pollTimer; + QThread *bearerThread; QMutex mutex; |