diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2019-12-18 18:17:38 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-03-03 14:36:28 -0800 |
commit | f6c1cebe42193a62fa0b9c6a881bb1a973b1b8a9 (patch) | |
tree | 73d32c1350b7bd278b4f6c2fdcc7716d5f383263 /src/corelib/plugin/qlibrary_p.h | |
parent | d9ca61bf0f6e544ad1fe2908e84c4a4966e5d0a1 (diff) |
QPluginLoader: rework the loading and the caching of instance
There was a race condition in accessing the cached instance factory
member, so rework loadPlugin() to return the cached or newly discovered
instance, with proper, atomic caching. Because I had to change that, I
took the opportunity to fix the QFactoryLoader code that calls
loadPlugin().
Note that QLibraryPrivate::loadPlugin() returns non-nullptr now if the
instance is known, which means the last return in QPluginLoader::load()
will convert to true, not false, if the instance got cached between the
earlier check and the call to loadPlugin(). That's probably what was
intended.
Task-number: QTBUG-39642
Change-Id: I46bf1f65e8db46afbde5fffd15e1a42d2b6cbf2c
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/plugin/qlibrary_p.h')
-rw-r--r-- | src/corelib/plugin/qlibrary_p.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h index db5afac98e..29724655a3 100644 --- a/src/corelib/plugin/qlibrary_p.h +++ b/src/corelib/plugin/qlibrary_p.h @@ -86,7 +86,7 @@ public: QString fullVersion; bool load(); - bool loadPlugin(); // loads and resolves instance + QtPluginInstanceFunction loadPlugin(); // loads and resolves instance bool unload(UnloadFlag flag = UnloadSys); void release(); QFunctionPointer resolve(const char *); @@ -100,8 +100,8 @@ public: static QStringList suffixes_sys(const QString &fullVersion); static QStringList prefixes_sys(); - QPointer<QObject> inst; - QtPluginInstanceFunction instance; + QPointer<QObject> inst; // used by QFactoryLoader + QAtomicPointer<std::remove_pointer<QtPluginInstanceFunction>::type> instanceFactory; QJsonObject metaData; QString errorString; |