ExtensionSystem: Provide guard object that is deleted before shutdown

Just before the plugin instances are deleted. Useful as the parent for
objects that should live "as long as possible".

Change-Id: I0d9446e50e444b4de066f48793ecc45cd45695ee
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2024-08-09 10:15:07 +02:00
parent 59520c6b3d
commit a25ae3d011
2 changed files with 37 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
#include "optionsparser.h"
#include "pluginmanager_p.h"
#include "pluginspec.h"
#include "shutdownguard.h"
#include <nanotrace/nanotrace.h>
@@ -235,6 +236,26 @@ using namespace Internal;
static Internal::PluginManagerPrivate *d = nullptr;
static PluginManager *m_instance = nullptr;
static QObject *m_shutdownGuard = nullptr;
/*!
Returns an object that can be used as the parent for objects that should be
destroyed just at the end of the applications lifetime.
The object is destroyed after all plugins' aboutToShutdown methods
have finished, just before the plugins are deleted.
Only use this from the application's main thread.
\sa ExtensionSystem::IPlugin::aboutToShutdown()
*/
QObject *shutdownGuard()
{
if (!m_shutdownGuard) {
QTC_CHECK(Utils::isMainThread());
m_shutdownGuard = new QObject;
}
return m_shutdownGuard;
}
/*!
Gets the unique plugin manager instance.
@@ -1056,6 +1077,8 @@ void PluginManagerPrivate::deleteAll()
Utils::futureSynchronizer()->isCancelOnWait(),
Utils::futureSynchronizer()->cancelAllFutures());
Utils::futureSynchronizer()->waitForFinished(); // Synchronize all futures from all plugins
delete m_shutdownGuard;
m_shutdownGuard = nullptr;
Utils::reverseForeach(loadQueue(), [this](PluginSpec *spec) {
loadPlugin(spec, PluginSpec::Deleted);
});

View File

@@ -0,0 +1,14 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "extensionsystem_global.h"
#include <QObject>
namespace ExtensionSystem {
EXTENSIONSYSTEM_EXPORT QObject *shutdownGuard();
} // namespace ExtensionSystem