forked from qt-creator/qt-creator
ExtensionSystem: Move shutdownGuard to Utils
So it can be used inside Utils which does not depend on ExtensionSystem. Change-Id: Iade7f2a8eb14b2fed59e10682cff9e56c29f990e Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
#include "optionsparser.h"
|
||||
#include "pluginmanager_p.h"
|
||||
#include "pluginspec.h"
|
||||
#include "shutdownguard.h"
|
||||
|
||||
#include <nanotrace/nanotrace.h>
|
||||
|
||||
@@ -21,6 +20,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/qtcsettings.h>
|
||||
#include <utils/shutdownguard.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/threadutils.h>
|
||||
|
||||
@@ -248,26 +248,6 @@ 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.
|
||||
@@ -1092,8 +1072,7 @@ void PluginManagerPrivate::deleteAll()
|
||||
Utils::futureSynchronizer()->isCancelOnWait(),
|
||||
Utils::futureSynchronizer()->cancelAllFutures());
|
||||
Utils::futureSynchronizer()->waitForFinished(); // Synchronize all futures from all plugins
|
||||
delete m_shutdownGuard;
|
||||
m_shutdownGuard = nullptr;
|
||||
triggerShutdownGuard();
|
||||
Utils::reverseForeach(loadQueue(), [this](PluginSpec *spec) {
|
||||
loadPlugin(spec, PluginSpec::Deleted);
|
||||
});
|
||||
|
@@ -150,6 +150,7 @@ add_qtc_library(Utils
|
||||
set_algorithm.h
|
||||
settingsaccessor.cpp settingsaccessor.h
|
||||
settingsselector.cpp settingsselector.h
|
||||
shutdownguard.cpp shutdownguard.h
|
||||
sizedarray.h
|
||||
smallstring.h
|
||||
smallstringfwd.h
|
||||
|
73
src/libs/utils/shutdownguard.cpp
Normal file
73
src/libs/utils/shutdownguard.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <shutdownguard.h>
|
||||
|
||||
#include <threadutils.h>
|
||||
#include <qtcassert.h>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class ShutdownGuardHolder final
|
||||
{
|
||||
public:
|
||||
~ShutdownGuardHolder()
|
||||
{
|
||||
if (!m_alreadyGone)
|
||||
triggerShutdownGuard();
|
||||
}
|
||||
|
||||
QObject *shutdownGuard()
|
||||
{
|
||||
QTC_CHECK(!m_alreadyGone);
|
||||
if (!m_shutdownGuard) {
|
||||
QTC_CHECK(Utils::isMainThread());
|
||||
m_shutdownGuard = new QObject;
|
||||
}
|
||||
return m_shutdownGuard;
|
||||
}
|
||||
|
||||
void triggerShutdownGuard()
|
||||
{
|
||||
m_alreadyGone = true;
|
||||
delete m_shutdownGuard;
|
||||
m_shutdownGuard = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
QObject *m_shutdownGuard = nullptr;
|
||||
bool m_alreadyGone = false;
|
||||
};
|
||||
|
||||
static ShutdownGuardHolder theShutdownGuardHolder;
|
||||
|
||||
/*!
|
||||
Destroys the shutdown guard object and consequently all
|
||||
objects guarded by it.
|
||||
|
||||
In a normal run of the application this function is called
|
||||
automatically at the appropriate time.
|
||||
*/
|
||||
|
||||
void triggerShutdownGuard()
|
||||
{
|
||||
return theShutdownGuardHolder.triggerShutdownGuard();
|
||||
}
|
||||
|
||||
/*!
|
||||
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()
|
||||
{
|
||||
return theShutdownGuardHolder.shutdownGuard();
|
||||
}
|
||||
|
||||
} // Utils
|
@@ -3,13 +3,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "extensionsystem_global.h"
|
||||
#include "utils_global.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace ExtensionSystem {
|
||||
namespace Utils {
|
||||
|
||||
EXTENSIONSYSTEM_EXPORT QObject *shutdownGuard();
|
||||
QTCREATOR_UTILS_EXPORT QObject *shutdownGuard();
|
||||
|
||||
// Called from PluginManagerPrivate::deleteAll()
|
||||
QTCREATOR_UTILS_EXPORT void triggerShutdownGuard();
|
||||
|
||||
template <class T>
|
||||
class GuardedObject
|
||||
@@ -31,4 +34,4 @@ private:
|
||||
T *m_object;
|
||||
};
|
||||
|
||||
} // namespace ExtensionSystem
|
||||
} // namespace Utils
|
@@ -271,6 +271,8 @@ QtcLibrary {
|
||||
"result.h",
|
||||
"savefile.cpp",
|
||||
"savefile.h",
|
||||
"shutdownguard.cpp",
|
||||
"shutdownguard.h",
|
||||
"scopedswap.h",
|
||||
"scopedtimer.cpp",
|
||||
"scopedtimer.h",
|
||||
|
@@ -9,9 +9,8 @@
|
||||
#include "ioutputpane.h"
|
||||
#include "outputwindow.h"
|
||||
|
||||
#include <extensionsystem/shutdownguard.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/shutdownguard.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QFont>
|
||||
@@ -100,7 +99,7 @@ private:
|
||||
static MessageOutputWindow *messageOutputWindow()
|
||||
{
|
||||
static QPointer<MessageOutputWindow> theMessageOutputWindow
|
||||
= new MessageOutputWindow(ExtensionSystem::shutdownGuard());
|
||||
= new MessageOutputWindow(Utils::shutdownGuard());
|
||||
return theMessageOutputWindow.get();
|
||||
}
|
||||
|
||||
@@ -124,7 +123,7 @@ static void showOutputPane(Flag flags)
|
||||
static void writeImpl(const QString &text, Flag flags)
|
||||
{
|
||||
// Make sure this end up in the GUI thread.
|
||||
QMetaObject::invokeMethod(ExtensionSystem::shutdownGuard(), [text, flags] {
|
||||
QMetaObject::invokeMethod(Utils::shutdownGuard(), [text, flags] {
|
||||
QTC_ASSERT(messageOutputWindow(), return);
|
||||
showOutputPane(flags);
|
||||
messageOutputWindow()->append(text + '\n');
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <extensionsystem/pluginspec.h>
|
||||
#include <extensionsystem/shutdownguard.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/filepath.h>
|
||||
@@ -27,6 +26,7 @@
|
||||
#include <utils/store.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/stylehelper.h>
|
||||
#include <utils/shutdownguard.h>
|
||||
#include <utils/threadutils.h>
|
||||
|
||||
#include <nanotrace/nanotrace.h>
|
||||
@@ -114,7 +114,7 @@ static SessionManagerPrivate *d = nullptr;
|
||||
|
||||
SessionManager *sessionManager()
|
||||
{
|
||||
static ExtensionSystem::GuardedObject<SessionManager> theSessionManager;
|
||||
static GuardedObject<SessionManager> theSessionManager;
|
||||
return theSessionManager.get();
|
||||
}
|
||||
|
||||
|
@@ -13,8 +13,6 @@
|
||||
#include <coreplugin/helpmanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <extensionsystem/shutdownguard.h>
|
||||
|
||||
#include <projectexplorer/devicesupport/devicemanager.h>
|
||||
#include <projectexplorer/devicesupport/idevicefactory.h>
|
||||
#include <projectexplorer/devicesupport/idevicewidget.h>
|
||||
@@ -23,6 +21,7 @@
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/portlist.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/shutdownguard.h>
|
||||
|
||||
#include <solutions/tasking/tasktree.h>
|
||||
|
||||
@@ -628,7 +627,7 @@ void IosDeviceManager::updateUserModeDevices()
|
||||
|
||||
IosDeviceManager *IosDeviceManager::instance()
|
||||
{
|
||||
static IosDeviceManager *theInstance = new IosDeviceManager(ExtensionSystem::shutdownGuard());
|
||||
static IosDeviceManager *theInstance = new IosDeviceManager(Utils::shutdownGuard());
|
||||
return theInstance;
|
||||
}
|
||||
|
||||
|
@@ -16,14 +16,13 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <extensionsystem/shutdownguard.h>
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include <utils/commandline.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/shutdownguard.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
@@ -213,7 +212,7 @@ VcsCommand *VcsBaseClientImpl::createVcsCommand(const FilePath &defaultWorkingDi
|
||||
const Environment &environment)
|
||||
{
|
||||
auto command = new VcsCommand(defaultWorkingDir, environment);
|
||||
command->setParent(ExtensionSystem::shutdownGuard());
|
||||
command->setParent(Utils::shutdownGuard());
|
||||
return command;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user