DolphinQt: Properly lock CPU before accessing emulated memory
This fixes a problem I was having where using frame advance with the debugger open would frequently cause panic alerts about invalid addresses due to the CPU thread changing MSR.DR while the host thread was trying to access memory. To aid in tracking down all the places where we weren't properly locking the CPU, I've created a new type (in Core.h) that you have to pass as a reference or pointer to functions that require running as the CPU thread.
This commit is contained in:
1 parent
efed037c4a
commit
7cecb28bdf
79 files changed
+1796
-1184
No files matched your search
@@ -92,6 +92,33 @@ enum class ConsoleType : u32
|
||||
ReservedTDEVSystem = 0x20000007,
|
||||
};
|
||||
|
||||
// Run a function as the CPU thread. This is an RAII alternative to the RunAsCPUThread function.
|
||||
//
|
||||
// If constructed from the Host thread, the CPU thread is paused and the current thread temporarily
|
||||
// becomes the CPU thread.
|
||||
// If constructed from the CPU thread, nothing special happens.
|
||||
//
|
||||
// This should only be constructed from the CPU thread or the host thread.
|
||||
//
|
||||
// Some functions use a parameter of this type to indicate that the function should only be called
|
||||
// from the CPU thread. If the parameter is a pointer, the function has a fallback for being called
|
||||
// from the wrong thread (with the argument being set to nullptr).
|
||||
class CPUThreadGuard final
|
||||
{
|
||||
public:
|
||||
CPUThreadGuard();
|
||||
~CPUThreadGuard();
|
||||
|
||||
CPUThreadGuard(const CPUThreadGuard&) = delete;
|
||||
CPUThreadGuard(CPUThreadGuard&&) = delete;
|
||||
CPUThreadGuard& operator=(const CPUThreadGuard&) = delete;
|
||||
CPUThreadGuard& operator=(CPUThreadGuard&&) = delete;
|
||||
|
||||
private:
|
||||
const bool m_was_cpu_thread;
|
||||
bool m_was_unpaused = false;
|
||||
};
|
||||
|
||||
bool Init(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi);
|
||||
void Stop();
|
||||
void Shutdown();
|
||||
|
||||
Reference in new issue
Block a user