Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quitting issue again #1876

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
bool running() { return m_running; }
const bool *runningPtr() { return &m_running; }
bool quitting() { return m_quitting; }
bool terminating() { return m_terminating; }
int exitCode() { return m_exitCode; }
bool emergencyExit() { return m_emergencyExit; }
[[gnu::cold]] void pause(bool exception = false) {
Expand All @@ -174,11 +175,16 @@
m_eventBus->signal(Events::ExecutionFlow::Pause{exception});
}
void resume() {
if (m_running) return;
if (m_running || m_terminating) return;
m_running = true;
m_eventBus->signal(Events::ExecutionFlow::Run{});
}
virtual void testQuit(int code) = 0;
[[gnu::cold]] void terminateSignalSafe() {

Check warning on line 183 in src/core/system.h

View check run for this annotation

Codecov / codecov/patch

src/core/system.h#L183

Added line #L183 was not covered by tests
// about the only thing signal handlers can do safely is switch a flag
m_terminating = true;
m_running = false;
}

Check warning on line 187 in src/core/system.h

View check run for this annotation

Codecov / codecov/patch

src/core/system.h#L185-L187

Added lines #L185 - L187 were not covered by tests
[[gnu::cold]] void quit(int code = 0) {
m_quitting = true;
pause();
Expand Down Expand Up @@ -259,6 +265,7 @@
std::string m_currentLocale;
bool m_running = false;
bool m_quitting = false;
bool m_terminating = false;
int m_exitCode = 0;
struct LocaleInfo {
const std::string filename;
Expand Down
19 changes: 11 additions & 8 deletions src/main/main.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***************************************************************************

Check notice on line 1 in src/main/main.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 8.13 to 7.33, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
* Copyright (C) 2019 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -166,6 +166,10 @@
std::function<void()> f;
};

void handleSignal(int signal) {
PCSX::g_system->terminateSignalSafe();
}

Check warning on line 171 in src/main/main.cc

View check run for this annotation

Codecov / codecov/patch

src/main/main.cc#L169-L171

Added lines #L169 - L171 were not covered by tests

int pcsxMain(int argc, char **argv) {
ZoneScoped;
// Command line arguments are parsed after this point.
Expand Down Expand Up @@ -193,11 +197,10 @@
// enabled as much as possible.
SystemImpl *system = new SystemImpl(args);
PCSX::g_system = system;
static std::atomic_bool scheduledQuit = false;
auto sigint = std::signal(SIGINT, [](auto signal) { scheduledQuit = true; });
auto sigterm = std::signal(SIGTERM, [](auto signal) { scheduledQuit = true; });
auto sigint = std::signal(SIGINT, handleSignal);
auto sigterm = std::signal(SIGTERM, handleSignal);
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
std::signal(SIGPIPE, SIG_IGN);
#endif
const auto &logfileArgOpt = args.get<std::string>("logfile");
const PCSX::u8string logfileArg = MAKEU8(logfileArgOpt.has_value() ? logfileArgOpt->c_str() : "");
Expand Down Expand Up @@ -455,10 +458,10 @@
// when the emulator is paused.
s_ui->update();
}
if (scheduledQuit) {
PCSX::g_system->quit(-1);
return exitCode;
}
if (system->terminating()) {
PCSX::g_system->quit(-1);
return exitCode;

Check warning on line 463 in src/main/main.cc

View check run for this annotation

Codecov / codecov/patch

src/main/main.cc#L462-L463

Added lines #L462 - L463 were not covered by tests
}
}
} catch (...) {
// This will ensure we don't do certain cleanups that are awaiting other tasks,
Expand Down
Loading