DolphinQt: Fix the panic alert deadlock, GPU thread edition

The fix in ef77872 worked for panic alerts from
the CPU thread, but there were still problems with
panic alerts from the GPU thread in dual core mode.
This change attempts to fix those.
This commit is contained in:
JosJuice
2020-04-25 00:26:51 +02:00
parent 07fd17445c
commit 3367e5e026
5 changed files with 59 additions and 21 deletions

View File

@ -3,6 +3,8 @@
#include "DolphinQt/Host.h"
#include <functional>
#include <QAbstractEventDispatcher>
#include <QApplication>
#include <QLocale>
@ -85,6 +87,19 @@ void Host::SetMainWindowHandle(void* handle)
m_main_window_handle = handle;
}
static void RunWithGPUThreadInactive(std::function<void()> f)
{
// If we are the GPU thread in dual core mode, we cannot safely call
// RunAsCPUThread, since RunAsCPUThread will need to pause the GPU thread
// and the GPU thread is waiting for us to finish. Fortunately, if we know
// that the GPU thread is waiting for us, we can just run f directly.
if (Core::IsGPUThread())
f();
else
Core::RunAsCPUThread(std::move(f));
}
bool Host::GetRenderFocus()
{
#ifdef _WIN32
@ -107,10 +122,12 @@ void Host::SetRenderFocus(bool focus)
{
m_render_focus = focus;
if (g_renderer && m_render_fullscreen && g_ActiveConfig.ExclusiveFullscreenEnabled())
Core::RunAsCPUThread([focus] {
{
RunWithGPUThreadInactive([focus] {
if (!Config::Get(Config::MAIN_RENDER_TO_MAIN))
g_renderer->SetFullscreen(focus);
});
}
}
void Host::SetRenderFullFocus(bool focus)
@ -138,7 +155,9 @@ void Host::SetRenderFullscreen(bool fullscreen)
if (g_renderer && g_renderer->IsFullscreen() != fullscreen &&
g_ActiveConfig.ExclusiveFullscreenEnabled())
Core::RunAsCPUThread([fullscreen] { g_renderer->SetFullscreen(fullscreen); });
{
RunWithGPUThreadInactive([fullscreen] { g_renderer->SetFullscreen(fullscreen); });
}
}
void Host::ResizeSurface(int new_width, int new_height)