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

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