2018-10-28 17:31:13 -05:00
|
|
|
using Ryujinx.Common;
|
2018-09-18 18:36:43 -05:00
|
|
|
|
2018-12-17 23:33:36 -06:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Threading
|
2018-09-18 18:36:43 -05:00
|
|
|
{
|
|
|
|
class KCoreContext
|
|
|
|
{
|
2018-12-06 05:16:24 -06:00
|
|
|
private KScheduler _scheduler;
|
2018-09-18 18:36:43 -05:00
|
|
|
|
2018-12-06 05:16:24 -06:00
|
|
|
private HleCoreManager _coreManager;
|
2018-09-18 18:36:43 -05:00
|
|
|
|
|
|
|
public bool ContextSwitchNeeded { get; private set; }
|
|
|
|
|
2018-11-28 16:18:09 -06:00
|
|
|
public long LastContextSwitchTime { get; private set; }
|
|
|
|
|
|
|
|
public long TotalIdleTimeTicks { get; private set; } //TODO
|
|
|
|
|
2018-09-18 18:36:43 -05:00
|
|
|
public KThread CurrentThread { get; private set; }
|
|
|
|
public KThread SelectedThread { get; private set; }
|
|
|
|
|
2018-12-06 05:16:24 -06:00
|
|
|
public KCoreContext(KScheduler scheduler, HleCoreManager coreManager)
|
2018-09-18 18:36:43 -05:00
|
|
|
{
|
2018-12-06 05:16:24 -06:00
|
|
|
_scheduler = scheduler;
|
|
|
|
_coreManager = coreManager;
|
2018-09-18 18:36:43 -05:00
|
|
|
}
|
|
|
|
|
2018-12-06 05:16:24 -06:00
|
|
|
public void SelectThread(KThread thread)
|
2018-09-18 18:36:43 -05:00
|
|
|
{
|
2018-12-06 05:16:24 -06:00
|
|
|
SelectedThread = thread;
|
2018-09-18 18:36:43 -05:00
|
|
|
|
2018-09-19 10:16:20 -05:00
|
|
|
if (SelectedThread != CurrentThread)
|
|
|
|
{
|
|
|
|
ContextSwitchNeeded = true;
|
|
|
|
}
|
2018-09-18 18:36:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateCurrentThread()
|
|
|
|
{
|
|
|
|
ContextSwitchNeeded = false;
|
|
|
|
|
2018-11-28 16:18:09 -06:00
|
|
|
LastContextSwitchTime = PerformanceCounter.ElapsedMilliseconds;
|
|
|
|
|
2018-09-18 18:36:43 -05:00
|
|
|
CurrentThread = SelectedThread;
|
2018-11-28 16:18:09 -06:00
|
|
|
|
|
|
|
if (CurrentThread != null)
|
|
|
|
{
|
2018-12-06 05:16:24 -06:00
|
|
|
long currentTime = PerformanceCounter.ElapsedMilliseconds;
|
2018-11-28 16:18:09 -06:00
|
|
|
|
2018-12-06 05:16:24 -06:00
|
|
|
CurrentThread.TotalTimeRunning += currentTime - CurrentThread.LastScheduledTime;
|
|
|
|
CurrentThread.LastScheduledTime = currentTime;
|
2018-11-28 16:18:09 -06:00
|
|
|
}
|
2018-09-18 18:36:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ContextSwitch()
|
|
|
|
{
|
|
|
|
ContextSwitchNeeded = false;
|
|
|
|
|
2018-11-28 16:18:09 -06:00
|
|
|
LastContextSwitchTime = PerformanceCounter.ElapsedMilliseconds;
|
|
|
|
|
2018-09-18 18:36:43 -05:00
|
|
|
if (CurrentThread != null)
|
|
|
|
{
|
2018-12-06 05:16:24 -06:00
|
|
|
_coreManager.Reset(CurrentThread.Context.Work);
|
2018-09-18 18:36:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
CurrentThread = SelectedThread;
|
|
|
|
|
|
|
|
if (CurrentThread != null)
|
|
|
|
{
|
2018-12-06 05:16:24 -06:00
|
|
|
long currentTime = PerformanceCounter.ElapsedMilliseconds;
|
2018-11-28 16:18:09 -06:00
|
|
|
|
2018-12-06 05:16:24 -06:00
|
|
|
CurrentThread.TotalTimeRunning += currentTime - CurrentThread.LastScheduledTime;
|
|
|
|
CurrentThread.LastScheduledTime = currentTime;
|
2018-11-28 16:18:09 -06:00
|
|
|
|
2018-09-18 18:36:43 -05:00
|
|
|
CurrentThread.ClearExclusive();
|
|
|
|
|
2018-12-06 05:16:24 -06:00
|
|
|
_coreManager.Set(CurrentThread.Context.Work);
|
2018-09-18 18:36:43 -05:00
|
|
|
|
|
|
|
CurrentThread.Context.Execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|