From f6b30722fa166fa1ed9ea0ad14bdb6e757317932 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Wed, 1 Jun 2011 16:35:43 +0100 Subject: bearer: run the bearer engines in their own worker thread The original architecture of the QtNetwork bearer support hosted the engines in the application's main thread, but this causes some problems. If the QNetworkConfigurationManager is constructed in a worker thread, then it is populated asynchronously without any notification when it is done (the app gets incomplete or missing results) Fixing that by restoring the earlier behaviour of using blocking queued connections to wait for the lists to be populated caused a regression, as some applications deadlock because the main thread is waiting on the worker thread at this time. By introducing a dedicated worker thread for the bearer engines, QNetworkConfigurationManager can be safely constructed in any thread while using blocking queued connections internally. Task-number: QTBUG-18795 Change-Id: Iaa1706d44b02b42057c100b0b399364175af2ddb Reviewed-by: mread (cherry picked from commit 5f879c55e531165cc2569b03c3796d0f33d0a0b7) Reviewed-by: Jonas Gastal Reviewed-by: Murray Read Reviewed-by: Alex --- src/network/bearer/qnetworkconfigmanager.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/network/bearer/qnetworkconfigmanager.cpp') diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index e66581169f..2646f0c4ea 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -60,8 +60,9 @@ Q_GLOBAL_STATIC(QMutex, connManager_mutex) static void connManager_cleanup() { // this is not atomic or thread-safe! - delete connManager_ptr.load(); - connManager_ptr.store(0); + QNetworkConfigurationManagerPrivate *cmp = connManager_ptr.fetchAndStoreAcquire(0); + if (cmp) + cmp->cleanup(); } void QNetworkConfigurationManagerPrivate::addPostRoutine() @@ -80,12 +81,12 @@ QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() if (QCoreApplicationPrivate::mainThread() == QThread::currentThread()) { // right thread or no main thread yet ptr->addPostRoutine(); - ptr->updateConfigurations(); + ptr->initialize(); } else { // wrong thread, we need to make the main thread do this QObject *obj = new QObject; QObject::connect(obj, SIGNAL(destroyed()), ptr, SLOT(addPostRoutine()), Qt::DirectConnection); - ptr->updateConfigurations(); // this moves us to the main thread + ptr->initialize(); // this moves us to the right thread obj->moveToThread(QCoreApplicationPrivate::mainThread()); obj->deleteLater(); } -- cgit v1.2.3