Просмотр исходного кода

Somewhat better implementation of thread yield

gdkchan 7 лет назад
Родитель
Сommit
aa75957ce2

+ 25 - 15
Ryujinx.Core/OsHle/Handles/KProcessScheduler.cs

@@ -197,30 +197,40 @@ namespace Ryujinx.Core.OsHle.Handles
 
 
             if (NeedsReschedule)
             if (NeedsReschedule)
             {
             {
-                PrintDbgThreadInfo(Thread, "yielded execution.");
-
-                lock (SchedLock)
-                {
-                    int ActualCore = Thread.ActualCore;
+                Yield(Thread, Thread.ActualPriority - 1);
+            }
+        }
 
 
-                    SchedulerThread NewThread = WaitingToRun.Pop(ActualCore, Thread.ActualPriority);
+        public void Yield(KThread Thread)
+        {
+            Yield(Thread, Thread.ActualPriority);
+        }
 
 
-                    if (NewThread == null)
-                    {
-                        PrintDbgThreadInfo(Thread, "resumed because theres nothing better to run.");
+        private void Yield(KThread Thread, int MinPriority)
+        {
+            PrintDbgThreadInfo(Thread, "yielded execution.");
 
 
-                        return;
-                    }
+            lock (SchedLock)
+            {
+                int ActualCore = Thread.ActualCore;
 
 
-                    NewThread.Thread.ActualCore = ActualCore;
+                SchedulerThread NewThread = WaitingToRun.Pop(ActualCore, MinPriority);
 
 
-                    CoreThreads[ActualCore] = NewThread.Thread;
+                if (NewThread == null)
+                {
+                    PrintDbgThreadInfo(Thread, "resumed because theres nothing better to run.");
 
 
-                    RunThread(NewThread);
+                    return;
                 }
                 }
 
 
-                Resume(Thread);
+                NewThread.Thread.ActualCore = ActualCore;
+
+                CoreThreads[ActualCore] = NewThread.Thread;
+
+                RunThread(NewThread);
             }
             }
+
+            Resume(Thread);
         }
         }
 
 
         public void Resume(KThread Thread)
         public void Resume(KThread Thread)

+ 2 - 2
Ryujinx.Core/OsHle/Handles/ThreadQueue.cs

@@ -2,7 +2,7 @@ namespace Ryujinx.Core.OsHle.Handles
 {
 {
     class ThreadQueue
     class ThreadQueue
     {
     {
-        private const int LowestPriority = 0x40;
+        private const int LowestPriority = 0x3f;
 
 
         private SchedulerThread Head;
         private SchedulerThread Head;
 
 
@@ -63,7 +63,7 @@ namespace Ryujinx.Core.OsHle.Handles
                 {
                 {
                     KThread Thread = Curr.Thread;
                     KThread Thread = Curr.Thread;
 
 
-                    if (Thread.ActualPriority < MinPriority && (Thread.CoreMask & CoreMask) != 0)
+                    if (Thread.ActualPriority <= MinPriority && (Thread.CoreMask & CoreMask) != 0)
                     {
                     {
                         if (Prev != null)
                         if (Prev != null)
                         {
                         {

+ 1 - 1
Ryujinx.Core/OsHle/Kernel/SvcThread.cs

@@ -87,7 +87,7 @@ namespace Ryujinx.Core.OsHle.Kernel
 
 
             if (TimeoutNs == 0)
             if (TimeoutNs == 0)
             {
             {
-                Process.Scheduler.SetReschedule(CurrThread.ActualCore);
+                Process.Scheduler.Yield(CurrThread);
             }
             }
             else
             else
             {
             {

+ 1 - 1
Ryujinx.Core/OsHle/Kernel/SvcThreadSync.cs

@@ -206,7 +206,7 @@ namespace Ryujinx.Core.OsHle.Kernel
         {
         {
             lock (Process.ThreadSyncLock)
             lock (Process.ThreadSyncLock)
             {
             {
-                //This is the new thread that will not own the mutex.
+                //This is the new thread that will now own the mutex.
                 //If no threads are waiting for the lock, then it should be null.
                 //If no threads are waiting for the lock, then it should be null.
                 KThread OwnerThread = PopThread(CurrThread.MutexWaiters, x => x.MutexAddress == MutexAddress);
                 KThread OwnerThread = PopThread(CurrThread.MutexWaiters, x => x.MutexAddress == MutexAddress);