From 36617a6055d5e98a334ae16446f54dbfbd7815d7 Mon Sep 17 00:00:00 2001 From: Sour Date: Sat, 9 Jun 2018 18:47:11 -0400 Subject: [PATCH] Linux: Prevent infrequent freeze/crash when closing --- GUI.NET/Forms/frmMain.cs | 11 +++++++++++ Linux/LinuxKeyManager.cpp | 3 ++- Linux/LinuxKeyManager.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 8f741989..762ba813 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -242,6 +242,17 @@ namespace Mesen.GUI.Forms return; } + if(!_shuttingDown && Program.IsMono) { + //This appears to prevent Mono from locking up when closing the form + Task.Run(() => { + StopEmu(); + _shuttingDown = true; + this.BeginInvoke((Action)(() => this.Close())); + }); + e.Cancel = true; + return; + } + _shuttingDown = true; //Stop menu update timer, and process all pending events before stopping the core diff --git a/Linux/LinuxKeyManager.cpp b/Linux/LinuxKeyManager.cpp index bcf3e4b2..e7db03b7 100755 --- a/Linux/LinuxKeyManager.cpp +++ b/Linux/LinuxKeyManager.cpp @@ -270,6 +270,7 @@ LinuxKeyManager::LinuxKeyManager() LinuxKeyManager::~LinuxKeyManager() { _stopUpdateDeviceThread = true; + _stopSignal.Signal(); _updateDeviceThread.join(); } @@ -387,7 +388,7 @@ void LinuxKeyManager::StartUpdateDeviceThread() Console::Resume(); } - std::this_thread::sleep_for(std::chrono::duration(2000)); + _stopSignal.Wait(2000); } }); } diff --git a/Linux/LinuxKeyManager.h b/Linux/LinuxKeyManager.h index dd86e501..29155276 100755 --- a/Linux/LinuxKeyManager.h +++ b/Linux/LinuxKeyManager.h @@ -3,6 +3,7 @@ #include #include #include "../Core/IKeyManager.h" +#include "../Utilities/AutoResetEvent.h" class LinuxGameController; @@ -24,6 +25,7 @@ private: std::thread _updateDeviceThread; atomic _stopUpdateDeviceThread; + AutoResetEvent _stopSignal; bool _disableAllKeys; void StartUpdateDeviceThread();