diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 66c60fbf86..ac772fc308 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -410,12 +410,13 @@ bool GPUCommon::InterpretList(DisplayList &list) { // TODO: Add check for displaylist debugger. const bool useFastRunLoop = !dumpThisFrame; while (gpuState == GPUSTATE_RUNNING) { - guard.lock(); - if (list.pc == list.stall) { - gpuState = GPUSTATE_STALL; - downcount = 0; + { + easy_guard innerGuard(listLock); + if (list.pc == list.stall) { + gpuState = GPUSTATE_STALL; + downcount = 0; + } } - guard.unlock(); if (useFastRunLoop) { FastRunLoop(list); @@ -423,14 +424,15 @@ bool GPUCommon::InterpretList(DisplayList &list) { SlowRunLoop(list); } - guard.lock(); - downcount = list.stall == 0 ? 0xFFFFFFF : (list.stall - list.pc) / 4; + { + easy_guard innerGuard(listLock); + downcount = list.stall == 0 ? 0xFFFFFFF : (list.stall - list.pc) / 4; - if (gpuState == GPUSTATE_STALL && list.stall != list.pc) { - // Unstalled. - gpuState = GPUSTATE_RUNNING; + if (gpuState == GPUSTATE_STALL && list.stall != list.pc) { + // Unstalled. + gpuState = GPUSTATE_RUNNING; + } } - guard.unlock(); } // We haven't run the op at list.pc, so it shouldn't count. diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 0e9d902534..0641a9fdca 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -52,12 +52,12 @@ protected: void ReapplyGfxStateInternal(); virtual void ProcessEvent(GPUEvent ev) = 0; + // Allows early unlocking with a guard. Do not double unlock. class easy_guard { public: easy_guard(recursive_mutex &mtx) : mtx_(mtx), locked_(true) { mtx_.lock(); } ~easy_guard() { if (locked_) mtx_.unlock(); } - void lock() { if (!locked_) mtx_.lock(); locked_ = true; } - void unlock() { if (locked_) mtx_.unlock(); locked_ = false; } + void unlock() { if (locked_) mtx_.unlock(); else Crash(); locked_ = false; } private: bool locked_;