From 9d77ff2064be61d2fdf2c034b13ef75cc4905bb3 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 24 Aug 2010 12:14:03 +1000 Subject: Fix race condition on bearer management initialisation. Defer initialisation and changing thread affinity until after the global static is constructed. Task-number: QTBUG-12686 --- src/network/bearer/qnetworkconfigmanager.cpp | 12 ++++++++++-- src/network/bearer/qnetworkconfigmanager_p.cpp | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 102b347..65014a6 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -54,7 +54,15 @@ Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() { - return connManager(); + static bool initialized = false; + + QNetworkConfigurationManagerPrivate *m = connManager(); + if (!initialized) { + initialized = true; + m->updateConfigurations(); + } + + return m; } /*! @@ -178,7 +186,7 @@ QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() QNetworkConfigurationManager::QNetworkConfigurationManager( QObject* parent ) : QObject(parent) { - QNetworkConfigurationManagerPrivate *priv = connManager(); + QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); connect(priv, SIGNAL(configurationAdded(QNetworkConfiguration)), this, SIGNAL(configurationAdded(QNetworkConfiguration))); diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index dd174bf..d388920 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -64,9 +64,6 @@ QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() { qRegisterMetaType("QNetworkConfiguration"); qRegisterMetaType("QNetworkConfigurationPrivatePointer"); - - moveToThread(QCoreApplicationPrivate::mainThread()); - updateConfigurations(); } QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() @@ -359,6 +356,13 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (sender()) return; + if (thread() != QCoreApplicationPrivate::mainThread()) { + if (thread() != QThread::currentThread()) + return; + + moveToThread(QCoreApplicationPrivate::mainThread()); + } + updating = false; #ifndef QT_NO_LIBRARY -- cgit v0.12