From c59b7050d94fe134601290cd36d03df63d0ae25b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 18 Sep 2016 23:27:10 +0200 Subject: [PATCH 1/2] MemoryUtil: Fix formatting clang-format really *wants* the two empty lines to be removed; otherwise, it will always flag MemoryUtil as needing formatting changes which is an annoyance when it is used as a git filter driver. --- Source/Core/Common/MemoryUtil.cpp | 1 - Source/Core/Common/MemoryUtil.h | 1 - 2 files changed, 2 deletions(-) diff --git a/Source/Core/Common/MemoryUtil.cpp b/Source/Core/Common/MemoryUtil.cpp index ce0d38cbcb9a..0c079a15b38b 100644 --- a/Source/Core/Common/MemoryUtil.cpp +++ b/Source/Core/Common/MemoryUtil.cpp @@ -33,7 +33,6 @@ namespace Common { - #if !defined(_WIN32) #include static uintptr_t RoundPage(uintptr_t addr) diff --git a/Source/Core/Common/MemoryUtil.h b/Source/Core/Common/MemoryUtil.h index fa41da297c96..1e2402f5d252 100644 --- a/Source/Core/Common/MemoryUtil.h +++ b/Source/Core/Common/MemoryUtil.h @@ -9,7 +9,6 @@ namespace Common { - void* AllocateExecutableMemory(size_t size, bool low = true); void* AllocateMemoryPages(size_t size); void FreeMemoryPages(void* ptr, size_t size); From 3cbf3bae972c25fe1673da80184337422d5c32ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 24 Sep 2016 21:17:34 +0200 Subject: [PATCH 2/2] MainNoGUI: Shut down cleanly on shutdown signal This is the same as PR #3991, but for MainNoGUI. nogui/headless will shut down cleanly on SIGINT and SIGTERM, just like it would when closing the render window. The default signal handler will be restored after a first shutdown signal so a second signal will exit Dolphin forcefully. --- Source/Core/DolphinWX/MainNoGUI.cpp | 33 +++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index c262d6244b8a..1d06ff559a29 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -6,12 +6,14 @@ #include #include #include +#include #include #include #include #include "Common/CommonTypes.h" #include "Common/Event.h" +#include "Common/Flag.h" #include "Common/Logging/LogManager.h" #include "Common/MsgHandler.h" @@ -31,7 +33,16 @@ static bool rendererHasFocus = true; static bool rendererIsFullscreen = false; -static bool running = true; +static Common::Flag s_running{true}; + +static void signal_handler(int) +{ + const char message[] = "A signal was received. A second signal will force Dolphin to stop.\n"; + if (write(STDERR_FILENO, message, sizeof(message)) < 0) + { + } + s_running.Clear(); +} class Platform { @@ -40,7 +51,7 @@ class Platform virtual void SetTitle(const std::string& title) {} virtual void MainLoop() { - while (running) + while (s_running.IsSet()) { Core::HostDispatchJobs(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -64,7 +75,7 @@ void Host_Message(int Id) { if (Id == WM_USER_STOP) { - running = false; + s_running.Clear(); updateMainFrameEvent.Set(); } } @@ -209,7 +220,7 @@ class PlatformX11 : public Platform } // The actual loop - while (running) + while (s_running.IsSet()) { XEvent event; KeySym key; @@ -275,7 +286,7 @@ class PlatformX11 : public Platform break; case ClientMessage: if ((unsigned long)event.xclient.data.l[0] == XInternAtom(dpy, "WM_DELETE_WINDOW", False)) - running = false; + s_running.Clear(); break; } } @@ -366,6 +377,14 @@ int main(int argc, char* argv[]) platform->Init(); + // Shut down cleanly on SIGINT and SIGTERM + struct sigaction sa; + sa.sa_handler = signal_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESETHAND; + sigaction(SIGINT, &sa, nullptr); + sigaction(SIGTERM, &sa, nullptr); + DolphinAnalytics::Instance()->ReportDolphinStart("nogui"); if (!BootManager::BootCore(argv[optind])) @@ -374,13 +393,13 @@ int main(int argc, char* argv[]) return 1; } - while (!Core::IsRunning() && running) + while (!Core::IsRunning() && s_running.IsSet()) { Core::HostDispatchJobs(); updateMainFrameEvent.Wait(); } - if (running) + if (s_running.IsSet()) platform->MainLoop(); Core::Stop();