mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
Fixed deadlock when switching game while paused
This commit is contained in:
parent
0d78c064f3
commit
972fc6a18b
4 changed files with 14 additions and 7 deletions
|
@ -102,8 +102,7 @@ void Emulator::Run()
|
|||
return;
|
||||
}
|
||||
|
||||
auto lock = _runLock.AcquireSafe();
|
||||
auto emulationLock = _emulationLock.AcquireSafe();
|
||||
_runLock.Acquire();
|
||||
|
||||
_stopFlag = false;
|
||||
_isRunAheadFrame = false;
|
||||
|
@ -151,6 +150,11 @@ void Emulator::Run()
|
|||
|
||||
_emulationThreadId = thread::id();
|
||||
|
||||
if(_runLock.IsLockedByCurrentThread()) {
|
||||
//Lock might not be held by current frame is _stopFlag was set to interrupt the thread
|
||||
_runLock.Release();
|
||||
}
|
||||
|
||||
PlatformUtilities::RestoreTimerResolution();
|
||||
}
|
||||
|
||||
|
@ -288,8 +292,6 @@ void Emulator::Stop(bool sendNotification)
|
|||
debugger->Run();
|
||||
}
|
||||
|
||||
_emulationLock.WaitForRelease();
|
||||
|
||||
if(_emuThread) {
|
||||
_emuThread->join();
|
||||
_emuThread.release();
|
||||
|
@ -686,8 +688,8 @@ void Emulator::WaitForPauseEnd()
|
|||
PlatformUtilities::DisableScreensaver();
|
||||
PlatformUtilities::EnableHighResolutionTimer();
|
||||
|
||||
_runLock.Acquire();
|
||||
if(!_stopFlag) {
|
||||
_runLock.Acquire();
|
||||
_notificationManager->SendNotification(ConsoleNotificationType::GameResumed);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,6 @@ private:
|
|||
|
||||
atomic<uint32_t> _lockCounter;
|
||||
SimpleLock _runLock;
|
||||
SimpleLock _emulationLock;
|
||||
SimpleLock _loadLock;
|
||||
|
||||
SimpleLock _debuggerLock;
|
||||
|
|
|
@ -37,6 +37,11 @@ bool SimpleLock::IsFree()
|
|||
return _lockCount == 0;
|
||||
}
|
||||
|
||||
bool SimpleLock::IsLockedByCurrentThread()
|
||||
{
|
||||
return _lockCount > 0 && _holderThreadID == _threadID;
|
||||
}
|
||||
|
||||
void SimpleLock::WaitForRelease()
|
||||
{
|
||||
//Wait until we are able to grab a lock, and then release it again
|
||||
|
@ -46,7 +51,7 @@ void SimpleLock::WaitForRelease()
|
|||
|
||||
void SimpleLock::Release()
|
||||
{
|
||||
if(_lockCount > 0 && _holderThreadID == _threadID) {
|
||||
if(IsLockedByCurrentThread()) {
|
||||
_lockCount--;
|
||||
if(_lockCount == 0) {
|
||||
_holderThreadID = std::thread::id();
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
|
||||
void Acquire();
|
||||
bool IsFree();
|
||||
bool IsLockedByCurrentThread();
|
||||
void WaitForRelease();
|
||||
void Release();
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue