summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/qpluginloader.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2019-12-18 18:45:36 -0800
committerThiago Macieira <thiago.macieira@intel.com>2020-03-03 14:36:32 -0800
commitae6f73e8566fa76470937aca737141183929a5ec (patch)
tree4a45798d9c4d6b1e5f163a4d215ce4988e76d1bc /src/corelib/plugin/qpluginloader.cpp
parentef92ac5636c2f0407fba8141c35ea61d391fd479 (diff)
QLibrary: introduce a mutex to protect non-atomic internals
And make pHnd atomic. The majority of the variables is updated in QLibraryPrivate::load_sys and updatePluginState(), which get the mutex protection. QLibraryPrivate::unload_sys() doesn't need a mutex protection because we have the refcounting. [ChangeLog][QtCore][QLibrary & QPluginLoader] Fixed a number of race conditions caused by having two QLibrary objects pointing to the same library being operated in different threads. Fixes: QTBUG-39642 Change-Id: I46bf1f65e8db46afbde5fffd15e1a5b3f5e74ea4 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/plugin/qpluginloader.cpp')
-rw-r--r--src/corelib/plugin/qpluginloader.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp
index dac8502dae..0e12793d5e 100644
--- a/src/corelib/plugin/qpluginloader.cpp
+++ b/src/corelib/plugin/qpluginloader.cpp
@@ -196,9 +196,7 @@ QObject *QPluginLoader::instance()
{
if (!isLoaded() && !load())
return 0;
- if (!d->inst && d->instance)
- d->inst = d->instance();
- return d->inst.data();
+ return d->pluginInstance();
}
/*!
@@ -233,7 +231,7 @@ bool QPluginLoader::load()
if (!d || d->fileName.isEmpty())
return false;
if (did_load)
- return d->pHnd && d->instance;
+ return d->pHnd && d->instanceFactory.loadAcquire();
if (!d->isPlugin())
return false;
did_load = true;
@@ -275,7 +273,7 @@ bool QPluginLoader::unload()
*/
bool QPluginLoader::isLoaded() const
{
- return d && d->pHnd && d->instance;
+ return d && d->pHnd && d->instanceFactory.loadRelaxed();
}
#if defined(QT_SHARED)