diff options
author | gdkchan <gab.dark.100@gmail.com> | 2021-05-11 13:18:50 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 13:18:50 -0300 |
commit | ebdbaa6db05057a5747cc96849922135a8b07994 (patch) | |
tree | 2b23b1fc2a541c0b020cf4e723de52187dfcdff8 /Ryujinx.HLE | |
parent | 701c4276599dbedb05f0a8b1ec19eb7b90157799 (diff) |
Fix a specific core migration bug on the scheduler (#2271)
Diffstat (limited to 'Ryujinx.HLE')
-rw-r--r-- | Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs b/Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs index e427f24d..0982ceff 100644 --- a/Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs +++ b/Ryujinx.HLE/HOS/Kernel/Threading/KScheduler.cs @@ -22,8 +22,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading private struct SchedulingState { - public bool NeedsScheduling; - public KThread SelectedThread; + public volatile bool NeedsScheduling; + public volatile KThread SelectedThread; } private SchedulingState _state; @@ -349,31 +349,29 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading nextThread ??= _idleThread; - if (currentThread == nextThread) + if (currentThread != nextThread) { - return; - } + long previousTicks = LastContextSwitchTime; + long currentTicks = PerformanceCounter.ElapsedTicks; + long ticksDelta = currentTicks - previousTicks; - long previousTicks = LastContextSwitchTime; - long currentTicks = PerformanceCounter.ElapsedTicks; - long ticksDelta = currentTicks - previousTicks; + currentThread.AddCpuTime(ticksDelta); - currentThread.AddCpuTime(ticksDelta); - - if (currentProcess != null) - { - currentProcess.AddCpuTime(ticksDelta); - } + if (currentProcess != null) + { + currentProcess.AddCpuTime(ticksDelta); + } - LastContextSwitchTime = currentTicks; + LastContextSwitchTime = currentTicks; - if (currentProcess != null) - { - _previousThread = !currentThread.TerminationRequested && currentThread.ActiveCore == _coreId ? currentThread : null; - } - else if (currentThread == _idleThread) - { - _previousThread = null; + if (currentProcess != null) + { + _previousThread = !currentThread.TerminationRequested && currentThread.ActiveCore == _coreId ? currentThread : null; + } + else if (currentThread == _idleThread) + { + _previousThread = null; + } } if (nextThread.CurrentCore != _coreId) @@ -469,6 +467,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { KThread currentThread = KernelStatic.GetCurrentThread(); + if (!currentThread.IsSchedulable) + { + return; + } + context.CriticalSection.Enter(); if (currentThread.SchedFlags != ThreadSchedState.Running) @@ -491,6 +494,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { KThread currentThread = KernelStatic.GetCurrentThread(); + if (!currentThread.IsSchedulable) + { + return; + } + context.CriticalSection.Enter(); if (currentThread.SchedFlags != ThreadSchedState.Running) @@ -550,6 +558,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading { KThread currentThread = KernelStatic.GetCurrentThread(); + if (!currentThread.IsSchedulable) + { + return; + } + context.CriticalSection.Enter(); if (currentThread.SchedFlags != ThreadSchedState.Running) |