Skip to content

Commit

Permalink
Scripting: fix deadlocks when using savestates
Browse files Browse the repository at this point in the history
  • Loading branch information
Felk committed Oct 22, 2021
1 parent 55099ed commit ddcf995
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static bool s_is_throttler_temp_disabled = false;
static std::atomic<double> s_last_actual_emulation_speed{1.0};
static bool s_frame_step = false;
static std::atomic<bool> s_stop_frame_step;
static std::atomic<bool> s_frame_advanced;

#ifdef USE_MEMORYWATCHER
static std::unique_ptr<MemoryWatcher> s_memory_watcher;
Expand Down Expand Up @@ -887,7 +888,10 @@ void Callback_FramePresented(double actual_emulation_speed)

s_drawn_frame++;
s_stop_frame_step.store(true);
API::GetEventHub().EmitEvent(API::Events::FrameAdvance{});
// Emitting the frame advanced event may cause work on the CPU thread,
// but synchronizing from the GPU thread with CPU thread deadlocks.
// So we cannot emit the event here and have to have the CPU thread do it.
s_frame_advanced.store(true);
}

// Called from VideoInterface::Update (CPU thread) at emulated field boundaries
Expand All @@ -909,6 +913,11 @@ void Callback_NewField()
CallOnStateChangedCallbacks(Core::GetState());
}
}
if (s_frame_advanced.load())
{
s_frame_advanced.store(false);
API::GetEventHub().EmitEvent(API::Events::FrameAdvance{});
}
}

void UpdateTitle(u32 ElapseTime)
Expand Down

0 comments on commit ddcf995

Please sign in to comment.