mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
DolphinQt: Improve the earlier panic alert deadlock fix
If the purpose of calling SetFullscreen using RunAsCPUThread is
to make sure that the GPU thread is paused, the fix in ef77872
is faulty when dual core is used and a panic alert comes from
the CPU thread. This change re-adds synchronization for that case.
This commit is contained in:
@ -44,6 +44,11 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
|
||||
const bool called_from_gpu_thread = Core::IsGPUThread();
|
||||
|
||||
std::optional<bool> r = RunOnObject(QApplication::instance(), [&] {
|
||||
// If we were called from the CPU/GPU thread, set us as the CPU/GPU thread.
|
||||
// This information is used in order to avoid deadlocks when calling e.g.
|
||||
// Host::SetRenderFocus or Core::RunAsCPUThread. (Host::SetRenderFocus
|
||||
// can get called automatically when a dialog steals the focus.)
|
||||
|
||||
Common::ScopeGuard cpu_scope_guard(&Core::UndeclareAsCPUThread);
|
||||
Common::ScopeGuard gpu_scope_guard(&Core::UndeclareAsGPUThread);
|
||||
|
||||
@ -53,20 +58,9 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
|
||||
gpu_scope_guard.Dismiss();
|
||||
|
||||
if (called_from_cpu_thread)
|
||||
{
|
||||
// If the panic alert that we are about to create steals the focus from RenderWidget,
|
||||
// Host::SetRenderFocus gets called, which can attempt to use RunAsCPUThread to get us out
|
||||
// of exclusive fullscreen. If we don't declare ourselves as the CPU thread, RunAsCPUThread
|
||||
// calls PauseAndLock, which causes a deadlock if the CPU thread is waiting on us returning.
|
||||
Core::DeclareAsCPUThread();
|
||||
}
|
||||
if (called_from_gpu_thread)
|
||||
{
|
||||
// We also need to avoid getting a deadlock when the GPU thread is waiting on us returning.
|
||||
// Declaring ourselves as the GPU thread does not alter the behavior of RunAsCPUThread or
|
||||
// PauseAndLock, but it does make Host::SetRenderFocus not call RunAsCPUThread.
|
||||
Core::DeclareAsGPUThread();
|
||||
}
|
||||
|
||||
ModalMessageBox message_box(QApplication::activeWindow(), Qt::ApplicationModal);
|
||||
message_box.setWindowTitle(QString::fromUtf8(caption));
|
||||
|
Reference in New Issue
Block a user