Skip to content

Commit

Permalink
Merge pull request PrismLauncher#3010 from Trial97/lock3
Browse files Browse the repository at this point in the history
  • Loading branch information
TayouVR authored Oct 30, 2024
2 parents 8faff9a + 11d4d94 commit 887e4a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "net/PasteUpload.h"
#include "pathmatcher/MultiMatcher.h"
#include "pathmatcher/SimplePrefixMatcher.h"
#include "tasks/Task.h"
#include "tools/GenericProfiler.h"
#include "ui/InstanceWindow.h"
#include "ui/MainWindow.h"
Expand Down Expand Up @@ -1397,6 +1398,7 @@ bool Application::launch(InstancePtr instance,
if (m_updateRunning) {
qDebug() << "Cannot launch instances while an update is running. Please try again when updates are completed.";
} else if (instance->canLaunch()) {
QMutexLocker locker(&m_instanceExtrasMutex);
auto& extras = m_instanceExtras[instance->id()];
auto window = extras.window;
if (window) {
Expand All @@ -1422,7 +1424,7 @@ bool Application::launch(InstancePtr instance,
connect(controller.get(), &LaunchController::failed, this, &Application::controllerFailed);
connect(controller.get(), &LaunchController::aborted, this, [this] { controllerFailed(tr("Aborted")); });
addRunningInstance();
controller->start();
QMetaObject::invokeMethod(controller.get(), &Task::start, Qt::QueuedConnection);
return true;
} else if (instance->isRunning()) {
showInstanceWindow(instance, "console");
Expand All @@ -1440,9 +1442,11 @@ bool Application::kill(InstancePtr instance)
qWarning() << "Attempted to kill instance" << instance->id() << ", which isn't running.";
return false;
}
QMutexLocker locker(&m_instanceExtrasMutex);
auto& extras = m_instanceExtras[instance->id()];
// NOTE: copy of the shared pointer keeps it alive
auto controller = extras.controller;
locker.unlock();
if (controller) {
return controller->abort();
}
Expand Down Expand Up @@ -1496,6 +1500,8 @@ void Application::controllerSucceeded()
if (!controller)
return;
auto id = controller->id();

QMutexLocker locker(&m_instanceExtrasMutex);
auto& extras = m_instanceExtras[id];

// on success, do...
Expand All @@ -1521,6 +1527,7 @@ void Application::controllerFailed(const QString& error)
if (!controller)
return;
auto id = controller->id();
QMutexLocker locker(&m_instanceExtrasMutex);
auto& extras = m_instanceExtras[id];

// on failure, do... nothing
Expand Down Expand Up @@ -1578,6 +1585,7 @@ InstanceWindow* Application::showInstanceWindow(InstancePtr instance, QString pa
if (!instance)
return nullptr;
auto id = instance->id();
QMutexLocker locker(&m_instanceExtrasMutex);
auto& extras = m_instanceExtras[id];
auto& window = extras.window;

Expand Down Expand Up @@ -1615,6 +1623,7 @@ void Application::on_windowClose()
m_openWindows--;
auto instWindow = qobject_cast<InstanceWindow*>(QObject::sender());
if (instWindow) {
QMutexLocker locker(&m_instanceExtrasMutex);
auto& extras = m_instanceExtras[instWindow->instanceId()];
extras.window = nullptr;
if (extras.controller) {
Expand Down
1 change: 1 addition & 0 deletions launcher/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class Application : public QApplication {
shared_qobject_ptr<LaunchController> controller;
};
std::map<QString, InstanceXtras> m_instanceExtras;
mutable QMutex m_instanceExtrasMutex;

// main state variables
size_t m_openWindows = 0;
Expand Down

0 comments on commit 887e4a9

Please sign in to comment.