From a37e62337dea943de65571baa88349dc50065622 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Mon, 8 Feb 2021 20:02:14 +0000 Subject: [PATCH] Common: Allow calling SysMessage off the main thread on linux DEV9 uses this when it can't open the selected adapter, and calls it from the EE thread --- common/include/PS2Eext.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/common/include/PS2Eext.h b/common/include/PS2Eext.h index 2666fca96e..71e31f4a01 100644 --- a/common/include/PS2Eext.h +++ b/common/include/PS2Eext.h @@ -20,6 +20,9 @@ #include #include +#include +#include + #if defined(_MSC_VER) #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0600 @@ -215,8 +218,31 @@ static void SysMessage(const char *fmt, ...) if (msg[strlen(msg) - 1] == '\n') msg[strlen(msg) - 1] = 0; - wxMessageDialog dialog(nullptr, msg, "Info", wxOK); - dialog.ShowModal(); + if (!wxIsMainThread()) + { + std::mutex dialogMutex; + std::condition_variable dialogCV; + bool dialogClosed = false; + + wxTheApp->CallAfter([&] { + wxMessageDialog dialog(nullptr, msg, "Info", wxOK); + dialog.ShowModal(); + + { + std::lock_guard dialogLock1(dialogMutex); + dialogClosed = true; + } + dialogCV.notify_all(); + }); + //Block until done + std::unique_lock dialogLock2(dialogMutex); + dialogCV.wait(dialogLock2, [&] { return dialogClosed; }); + } + else + { + wxMessageDialog dialog(nullptr, msg, "Info", wxOK); + dialog.ShowModal(); + } } #define ENTRY_POINT /* We don't need no stinkin' entry point! */