2018-02-04 15:08:20 -08:00
|
|
|
using ChocolArm64;
|
2018-05-13 23:01:10 -07:00
|
|
|
using System.Collections.Generic;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-08-16 16:47:36 -07:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-03-19 11:58:46 -07:00
|
|
|
class KThread : KSynchronizationObject
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
|
|
|
public AThread Thread { get; private set; }
|
|
|
|
|
2018-05-12 20:22:42 -07:00
|
|
|
public int CoreMask { get; set; }
|
|
|
|
|
2018-07-18 21:03:53 -07:00
|
|
|
public long MutexAddress { get; set; }
|
|
|
|
public long CondVarAddress { get; set; }
|
|
|
|
public long ArbiterWaitAddress { get; set; }
|
2018-04-21 12:07:16 -07:00
|
|
|
|
2018-05-15 18:36:08 -07:00
|
|
|
public bool CondVarSignaled { get; set; }
|
2018-07-18 21:03:53 -07:00
|
|
|
public bool ArbiterSignaled { get; set; }
|
2018-05-15 18:36:08 -07:00
|
|
|
|
2018-05-12 20:22:42 -07:00
|
|
|
private Process Process;
|
|
|
|
|
2018-05-13 23:01:10 -07:00
|
|
|
public List<KThread> MutexWaiters { get; private set; }
|
2018-04-21 12:07:16 -07:00
|
|
|
|
2018-04-24 11:57:39 -07:00
|
|
|
public KThread MutexOwner { get; set; }
|
2018-04-21 12:07:16 -07:00
|
|
|
|
|
|
|
public int ActualPriority { get; private set; }
|
|
|
|
public int WantedPriority { get; private set; }
|
|
|
|
|
2018-05-15 18:36:08 -07:00
|
|
|
public int ActualCore { get; set; }
|
|
|
|
public int ProcessorId { get; set; }
|
|
|
|
public int IdealCore { get; set; }
|
2018-04-18 19:52:23 -07:00
|
|
|
|
2018-04-21 12:07:16 -07:00
|
|
|
public int WaitHandle { get; set; }
|
2018-02-13 18:43:08 -08:00
|
|
|
|
2018-06-25 21:09:32 -07:00
|
|
|
public long LastPc { get; set; }
|
|
|
|
|
2018-08-16 16:47:36 -07:00
|
|
|
public int ThreadId { get; private set; }
|
2018-02-13 18:43:08 -08:00
|
|
|
|
2018-05-12 20:22:42 -07:00
|
|
|
public KThread(
|
|
|
|
AThread Thread,
|
|
|
|
Process Process,
|
2018-05-15 18:36:08 -07:00
|
|
|
int ProcessorId,
|
2018-08-16 16:47:36 -07:00
|
|
|
int Priority,
|
|
|
|
int ThreadId)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-05-15 18:36:08 -07:00
|
|
|
this.Thread = Thread;
|
|
|
|
this.Process = Process;
|
|
|
|
this.ProcessorId = ProcessorId;
|
|
|
|
this.IdealCore = ProcessorId;
|
2018-08-16 16:47:36 -07:00
|
|
|
this.ThreadId = ThreadId;
|
2018-05-12 20:22:42 -07:00
|
|
|
|
2018-05-13 23:01:10 -07:00
|
|
|
MutexWaiters = new List<KThread>();
|
|
|
|
|
2018-05-15 18:36:08 -07:00
|
|
|
CoreMask = 1 << ProcessorId;
|
2018-04-21 12:07:16 -07:00
|
|
|
|
|
|
|
ActualPriority = WantedPriority = Priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPriority(int Priority)
|
|
|
|
{
|
|
|
|
WantedPriority = Priority;
|
|
|
|
|
|
|
|
UpdatePriority();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdatePriority()
|
|
|
|
{
|
2018-06-21 19:05:42 -07:00
|
|
|
bool PriorityChanged;
|
2018-04-21 12:07:16 -07:00
|
|
|
|
2018-05-13 23:01:10 -07:00
|
|
|
lock (Process.ThreadSyncLock)
|
2018-04-21 12:07:16 -07:00
|
|
|
{
|
2018-06-21 19:05:42 -07:00
|
|
|
int OldPriority = ActualPriority;
|
|
|
|
|
|
|
|
int CurrPriority = WantedPriority;
|
|
|
|
|
2018-05-13 23:01:10 -07:00
|
|
|
foreach (KThread Thread in MutexWaiters)
|
2018-04-21 12:07:16 -07:00
|
|
|
{
|
2018-06-21 19:05:42 -07:00
|
|
|
int WantedPriority = Thread.WantedPriority;
|
|
|
|
|
|
|
|
if (CurrPriority > WantedPriority)
|
2018-05-12 20:22:42 -07:00
|
|
|
{
|
2018-06-21 19:05:42 -07:00
|
|
|
CurrPriority = WantedPriority;
|
2018-05-12 20:22:42 -07:00
|
|
|
}
|
|
|
|
}
|
2018-04-21 12:07:16 -07:00
|
|
|
|
2018-06-21 19:05:42 -07:00
|
|
|
PriorityChanged = CurrPriority != OldPriority;
|
|
|
|
|
2018-05-13 23:01:10 -07:00
|
|
|
ActualPriority = CurrPriority;
|
2018-06-21 19:05:42 -07:00
|
|
|
}
|
2018-05-12 20:22:42 -07:00
|
|
|
|
2018-06-21 19:05:42 -07:00
|
|
|
if (PriorityChanged)
|
|
|
|
{
|
2018-05-13 23:01:10 -07:00
|
|
|
Process.Scheduler.Resort(this);
|
2018-05-12 20:22:42 -07:00
|
|
|
|
2018-05-13 23:01:10 -07:00
|
|
|
MutexOwner?.UpdatePriority();
|
2018-04-21 12:07:16 -07:00
|
|
|
}
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|