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
This commit is contained in:
TheLastRar 2021-02-08 20:02:14 +00:00 committed by refractionpcsx2
parent 6177f89c3f
commit a37e62337d
1 changed files with 28 additions and 2 deletions

View File

@ -20,6 +20,9 @@
#include <string>
#include <cstdarg>
#include <mutex>
#include <condition_variable>
#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! */