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