diff options
author | gdkchan <gab.dark.100@gmail.com> | 2020-12-09 19:20:05 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-09 19:20:05 -0300 |
commit | 48278905d1470f89be31668c738397f569af156a (patch) | |
tree | 2e35b0695b33c8eb723f5948e3f6f040d84cfe76 /Ryujinx.HLE/HOS/Kernel/KernelStatic.cs | |
parent | 3484265d37732b32951709e5abfa52a260db349d (diff) |
Rewrite scheduler context switch code (#1786)
* Rewrite scheduler context switch code
* Fix race in UnmapIpcRestorePermission
* Fix thread exit issue that could leave the scheduler in a invalid state
* Change context switch method to not wait on guest thread, remove spin wait, use SignalAndWait to pass control
* Remove multi-core setting (it is always on now)
* Re-enable assert
* Remove multicore from default config and schema
* Fix race in KTimeManager
Diffstat (limited to 'Ryujinx.HLE/HOS/Kernel/KernelStatic.cs')
-rw-r--r-- | Ryujinx.HLE/HOS/Kernel/KernelStatic.cs | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs b/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs index c7deadae..2446ace4 100644 --- a/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs +++ b/Ryujinx.HLE/HOS/Kernel/KernelStatic.cs @@ -1,6 +1,9 @@ -using Ryujinx.HLE.HOS.Kernel.Threading; +using Ryujinx.HLE.HOS.Kernel.Common; +using Ryujinx.HLE.HOS.Kernel.Memory; +using Ryujinx.HLE.HOS.Kernel.Process; +using Ryujinx.HLE.HOS.Kernel.Threading; using System; -using System.Threading.Tasks; +using System.Threading; namespace Ryujinx.HLE.HOS.Kernel { @@ -9,30 +12,52 @@ namespace Ryujinx.HLE.HOS.Kernel [ThreadStatic] private static KernelContext Context; - public static void YieldUntilCompletion(Action action) + [ThreadStatic] + private static KThread CurrentThread; + + public static KernelResult StartInitialProcess( + KernelContext context, + ProcessCreationInfo creationInfo, + ReadOnlySpan<int> capabilities, + int mainThreadPriority, + ThreadStart customThreadStart) { - YieldUntilCompletion(Task.Factory.StartNew(action)); - } + KProcess process = new KProcess(context); - public static void YieldUntilCompletion(Task task) - { - KThread currentThread = Context.Scheduler.GetCurrentThread(); + KernelResult result = process.Initialize( + creationInfo, + capabilities, + context.ResourceLimit, + MemoryRegion.Service, + null, + customThreadStart); - Context.CriticalSection.Enter(); + if (result != KernelResult.Success) + { + return result; + } - currentThread.Reschedule(ThreadSchedState.Paused); + process.DefaultCpuCore = 3; - task.ContinueWith((antecedent) => - { - currentThread.Reschedule(ThreadSchedState.Running); - }); + context.Processes.TryAdd(process.Pid, process); - Context.CriticalSection.Leave(); + return process.Start(mainThreadPriority, 0x1000UL); } - internal static void SetKernelContext(KernelContext context) + internal static void SetKernelContext(KernelContext context, KThread thread) { Context = context; + CurrentThread = thread; + } + + internal static KThread GetCurrentThread() + { + return CurrentThread; + } + + internal static KProcess GetCurrentProcess() + { + return GetCurrentThread().Owner; } } } |