Somewhat better implementation of thread yield

This commit is contained in:
gdkchan 2018-06-09 18:19:14 -03:00
parent 7f5a8effbb
commit aa75957ce2
4 changed files with 32 additions and 22 deletions

View file

@ -196,6 +196,17 @@ namespace Ryujinx.Core.OsHle.Handles
} }
if (NeedsReschedule) if (NeedsReschedule)
{
Yield(Thread, Thread.ActualPriority - 1);
}
}
public void Yield(KThread Thread)
{
Yield(Thread, Thread.ActualPriority);
}
private void Yield(KThread Thread, int MinPriority)
{ {
PrintDbgThreadInfo(Thread, "yielded execution."); PrintDbgThreadInfo(Thread, "yielded execution.");
@ -203,7 +214,7 @@ namespace Ryujinx.Core.OsHle.Handles
{ {
int ActualCore = Thread.ActualCore; int ActualCore = Thread.ActualCore;
SchedulerThread NewThread = WaitingToRun.Pop(ActualCore, Thread.ActualPriority); SchedulerThread NewThread = WaitingToRun.Pop(ActualCore, MinPriority);
if (NewThread == null) if (NewThread == null)
{ {
@ -221,7 +232,6 @@ namespace Ryujinx.Core.OsHle.Handles
Resume(Thread); Resume(Thread);
} }
}
public void Resume(KThread Thread) public void Resume(KThread Thread)
{ {

View file

@ -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)
{ {

View file

@ -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
{ {

View file

@ -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);