Better locking in debug methods

This commit is contained in:
svc64 2023-09-30 11:22:30 +03:00
parent 40584e0e45
commit 81c399ec3e

View file

@ -1253,6 +1253,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
private void ThreadStart() private void ThreadStart()
{ {
_schedulerWaitEvent.WaitOne(); _schedulerWaitEvent.WaitOne();
DebugHalt.Reset();
KernelStatic.SetKernelContext(KernelContext, this); KernelStatic.SetKernelContext(KernelContext, this);
if (_customThreadStart != null) if (_customThreadStart != null)
@ -1439,18 +1440,26 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
public bool DebugStep() public bool DebugStep()
{ {
if (_debugState != (int)DebugState.Stopped || !Context.DebugStep()) lock (_activityOperationLock)
{
if (_debugState != (int)DebugState.Stopped
|| (_forcePauseFlags & ThreadSchedState.ThreadPauseFlag) == 0
|| !Context.DebugStep())
{ {
return false; return false;
} }
DebugHalt.Reset(); DebugHalt.Reset();
SetActivity(false); Resume(ThreadSchedState.ThreadPauseFlag);
DebugHalt.WaitOne(); DebugHalt.WaitOne();
return true; return true;
} }
}
public void DebugStop() public void DebugStop()
{
lock (_activityOperationLock)
{ {
if (Interlocked.CompareExchange(ref _debugState, (int)DebugState.Stopping, if (Interlocked.CompareExchange(ref _debugState, (int)DebugState.Stopping,
(int)DebugState.Running) != (int)DebugState.Running) (int)DebugState.Running) != (int)DebugState.Running)
@ -1458,13 +1467,21 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return; return;
} }
if ((_forcePauseFlags & ThreadSchedState.ThreadPauseFlag) == 0)
{
Suspend(ThreadSchedState.ThreadPauseFlag);
}
Context.DebugStop(); Context.DebugStop();
DebugHalt.WaitOne(); DebugHalt.WaitOne();
DebugHalt.Reset();
_debugState = (int)DebugState.Stopped; _debugState = (int)DebugState.Stopped;
} }
}
public void DebugContinue() public void DebugContinue()
{
lock (_activityOperationLock)
{ {
if (Interlocked.CompareExchange(ref _debugState, (int)DebugState.Running, if (Interlocked.CompareExchange(ref _debugState, (int)DebugState.Running,
(int)DebugState.Stopped) != (int)DebugState.Stopped) (int)DebugState.Stopped) != (int)DebugState.Stopped)
@ -1473,7 +1490,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
} }
Context.DebugContinue(); Context.DebugContinue();
SetActivity(false);
if ((_forcePauseFlags & ThreadSchedState.ThreadPauseFlag) != 0)
{
Resume(ThreadSchedState.ThreadPauseFlag);
}
}
} }
public DebugState GetDebugState() public DebugState GetDebugState()