diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2011-06-01 16:35:43 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-25 11:47:22 +0100 |
commit | f6b30722fa166fa1ed9ea0ad14bdb6e757317932 (patch) | |
tree | 881c9f0478de9cae4cb69ebb6642af8af0c748be /src/network/bearer/qnetworkconfigmanager.cpp | |
parent | e52ef6788b38f22ed024f1595392fd620e0773ef (diff) |
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 <jgastal@profusion.mobi>
Reviewed-by: Murray Read <ext-murray.2.read@nokia.com>
Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'src/network/bearer/qnetworkconfigmanager.cpp')
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
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(); } |