mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-22 18:15:11 +00:00
Somewhat better implementation of thread yield
This commit is contained in:
parent
7f5a8effbb
commit
aa75957ce2
4 changed files with 32 additions and 22 deletions
|
@ -197,30 +197,40 @@ namespace Ryujinx.Core.OsHle.Handles
|
|||
|
||||
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);
|
||||
|
||||
if (NewThread == null)
|
||||
{
|
||||
PrintDbgThreadInfo(Thread, "resumed because theres nothing better to run.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
NewThread.Thread.ActualCore = ActualCore;
|
||||
|
||||
CoreThreads[ActualCore] = NewThread.Thread;
|
||||
|
||||
RunThread(NewThread);
|
||||
return;
|
||||
}
|
||||
|
||||
Resume(Thread);
|
||||
NewThread.Thread.ActualCore = ActualCore;
|
||||
|
||||
CoreThreads[ActualCore] = NewThread.Thread;
|
||||
|
||||
RunThread(NewThread);
|
||||
}
|
||||
|
||||
Resume(Thread);
|
||||
}
|
||||
|
||||
public void Resume(KThread Thread)
|
||||
|
|
|
@ -2,7 +2,7 @@ namespace Ryujinx.Core.OsHle.Handles
|
|||
{
|
||||
class ThreadQueue
|
||||
{
|
||||
private const int LowestPriority = 0x40;
|
||||
private const int LowestPriority = 0x3f;
|
||||
|
||||
private SchedulerThread Head;
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace Ryujinx.Core.OsHle.Handles
|
|||
{
|
||||
KThread Thread = Curr.Thread;
|
||||
|
||||
if (Thread.ActualPriority < MinPriority && (Thread.CoreMask & CoreMask) != 0)
|
||||
if (Thread.ActualPriority <= MinPriority && (Thread.CoreMask & CoreMask) != 0)
|
||||
{
|
||||
if (Prev != null)
|
||||
{
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace Ryujinx.Core.OsHle.Kernel
|
|||
|
||||
if (TimeoutNs == 0)
|
||||
{
|
||||
Process.Scheduler.SetReschedule(CurrThread.ActualCore);
|
||||
Process.Scheduler.Yield(CurrThread);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace Ryujinx.Core.OsHle.Kernel
|
|||
{
|
||||
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.
|
||||
KThread OwnerThread = PopThread(CurrThread.MutexWaiters, x => x.MutexAddress == MutexAddress);
|
||||
|
||||
|
|
Loading…
Reference in a new issue