1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-02 21:32:02 +00:00
Ryujinx/Ryujinx.HLE/HOS/Kernel/KCoreContext.cs

81 lines
2.2 KiB
C#
Raw Normal View History

using Ryujinx.Common;
namespace Ryujinx.HLE.HOS.Kernel
{
class KCoreContext
{
2018-12-01 20:01:59 +00:00
private KScheduler _scheduler;
2018-12-01 20:01:59 +00:00
private HleCoreManager _coreManager;
public bool ContextSwitchNeeded { get; private set; }
public long LastContextSwitchTime { get; private set; }
public long TotalIdleTimeTicks { get; private set; } //TODO
public KThread CurrentThread { get; private set; }
public KThread SelectedThread { get; private set; }
2018-12-01 20:01:59 +00:00
public KCoreContext(KScheduler scheduler, HleCoreManager coreManager)
{
2018-12-01 20:24:37 +00:00
_scheduler = scheduler;
_coreManager = coreManager;
}
2018-12-01 20:01:59 +00:00
public void SelectThread(KThread thread)
{
2018-12-01 20:01:59 +00:00
SelectedThread = thread;
if (SelectedThread != CurrentThread)
{
ContextSwitchNeeded = true;
}
}
public void UpdateCurrentThread()
{
ContextSwitchNeeded = false;
LastContextSwitchTime = PerformanceCounter.ElapsedMilliseconds;
CurrentThread = SelectedThread;
if (CurrentThread != null)
{
2018-12-01 20:01:59 +00:00
long currentTime = PerformanceCounter.ElapsedMilliseconds;
2018-12-01 20:01:59 +00:00
CurrentThread.TotalTimeRunning += currentTime - CurrentThread.LastScheduledTime;
CurrentThread.LastScheduledTime = currentTime;
}
}
public void ContextSwitch()
{
ContextSwitchNeeded = false;
LastContextSwitchTime = PerformanceCounter.ElapsedMilliseconds;
if (CurrentThread != null)
{
2018-12-01 20:01:59 +00:00
_coreManager.Reset(CurrentThread.Context.Work);
}
CurrentThread = SelectedThread;
if (CurrentThread != null)
{
2018-12-01 20:01:59 +00:00
long currentTime = PerformanceCounter.ElapsedMilliseconds;
2018-12-01 20:01:59 +00:00
CurrentThread.TotalTimeRunning += currentTime - CurrentThread.LastScheduledTime;
CurrentThread.LastScheduledTime = currentTime;
CurrentThread.ClearExclusive();
2018-12-01 20:01:59 +00:00
_coreManager.Set(CurrentThread.Context.Work);
CurrentThread.Context.Execute();
}
}
}
}