Simplify easy_guard to avoid coding errors.

This commit is contained in:
Unknown W. Brackets 2013-08-09 01:03:54 -07:00
parent 1226c3dbd9
commit e82bae3708
2 changed files with 15 additions and 13 deletions

View file

@ -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.

View file

@ -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_;