Fixed rare deadlock

This commit is contained in:
Sour 2018-07-22 16:17:15 -04:00
parent a13f2dd3a8
commit 82c4dc8316
2 changed files with 7 additions and 7 deletions

View file

@ -62,6 +62,7 @@ Console::Console(shared_ptr<Console> master, EmulationSettings* initialSettings)
KeyManager::SetSettings(_settings.get());
}
_pauseCounter = 0;
_model = NesModel::NTSC;
}
@ -622,8 +623,7 @@ void Console::Pause()
//When trying to pause/resume the slave, we need to pause/resume the master instead
_master->Pause();
} else {
_pauseLock.Acquire();
//Spin wait until emu pauses
_pauseCounter++;
_runLock.Acquire();
}
}
@ -635,7 +635,7 @@ void Console::Resume()
_master->Resume();
} else {
_runLock.Release();
_pauseLock.Release();
_pauseCounter--;
}
shared_ptr<Debugger> debugger = _debugger;
@ -744,12 +744,12 @@ void Console::Run()
//Sleep until we're ready to start the next frame
clockTimer.WaitUntil(targetTime);
if(!_pauseLock.IsFree()) {
if(_pauseCounter > 0) {
//Need to temporarely pause the emu (to save/load a state, etc.)
_runLock.Release();
//Spin wait until we are allowed to start again
_pauseLock.WaitForRelease();
while(_pauseCounter > 0) { }
_runLock.Acquire();
}
@ -876,7 +876,7 @@ bool Console::IsExecutionStopped()
//For slave CPU, return the master's state
return _master->IsPaused();
} else {
return _runLock.IsFree() || !_pauseLock.IsFree() || !_running;
return _runLock.IsFree() || (!_runLock.IsFree() && _pauseCounter > 0) || !_running;
}
}

View file

@ -42,10 +42,10 @@ enum class EventType;
class Console : public std::enable_shared_from_this<Console>
{
private:
SimpleLock _pauseLock;
SimpleLock _runLock;
SimpleLock _stopLock;
SimpleLock _debuggerLock;
atomic<uint32_t> _pauseCounter;
shared_ptr<RewindManager> _rewindManager;
shared_ptr<HistoryViewer> _historyViewer;