2022-05-31 15:29:35 -04:00
|
|
|
|
using Ryujinx.Cpu;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2019-10-07 23:48:49 -04:00
|
|
|
|
using System;
|
2019-07-14 16:50:11 -04:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
|
|
|
{
|
|
|
|
|
class StandardUserSystemClockCore : SystemClockCore
|
|
|
|
|
{
|
|
|
|
|
private StandardLocalSystemClockCore _localSystemClockCore;
|
|
|
|
|
private StandardNetworkSystemClockCore _networkSystemClockCore;
|
|
|
|
|
private bool _autoCorrectionEnabled;
|
2019-10-07 23:48:49 -04:00
|
|
|
|
private SteadyClockTimePoint _autoCorrectionTime;
|
|
|
|
|
private KEvent _autoCorrectionEvent;
|
2019-07-14 16:50:11 -04:00
|
|
|
|
|
2019-07-25 10:44:51 -04:00
|
|
|
|
public StandardUserSystemClockCore(StandardLocalSystemClockCore localSystemClockCore, StandardNetworkSystemClockCore networkSystemClockCore) : base(localSystemClockCore.GetSteadyClockCore())
|
2019-07-14 16:50:11 -04:00
|
|
|
|
{
|
|
|
|
|
_localSystemClockCore = localSystemClockCore;
|
|
|
|
|
_networkSystemClockCore = networkSystemClockCore;
|
|
|
|
|
_autoCorrectionEnabled = false;
|
2019-10-07 23:48:49 -04:00
|
|
|
|
_autoCorrectionTime = SteadyClockTimePoint.GetRandom();
|
|
|
|
|
_autoCorrectionEvent = null;
|
2019-07-14 16:50:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
protected override ResultCode Flush(SystemClockContext context)
|
2019-07-14 16:50:11 -04:00
|
|
|
|
{
|
2019-10-07 23:48:49 -04:00
|
|
|
|
// As UserSystemClock isn't a real system clock, this shouldn't happens.
|
|
|
|
|
throw new NotImplementedException();
|
2019-07-14 16:50:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 15:29:35 -04:00
|
|
|
|
public override ResultCode GetClockContext(ITickSource tickSource, out SystemClockContext context)
|
2019-07-14 16:50:11 -04:00
|
|
|
|
{
|
2022-05-31 15:29:35 -04:00
|
|
|
|
ResultCode result = ApplyAutomaticCorrection(tickSource, false);
|
2019-07-14 16:50:11 -04:00
|
|
|
|
|
|
|
|
|
context = new SystemClockContext();
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
2022-05-31 15:29:35 -04:00
|
|
|
|
return _localSystemClockCore.GetClockContext(tickSource, out context);
|
2019-07-14 16:50:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
public override ResultCode SetClockContext(SystemClockContext context)
|
2019-07-14 16:50:11 -04:00
|
|
|
|
{
|
|
|
|
|
return ResultCode.NotImplemented;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 15:29:35 -04:00
|
|
|
|
private ResultCode ApplyAutomaticCorrection(ITickSource tickSource, bool autoCorrectionEnabled)
|
2019-07-14 16:50:11 -04:00
|
|
|
|
{
|
|
|
|
|
ResultCode result = ResultCode.Success;
|
|
|
|
|
|
2022-05-31 15:29:35 -04:00
|
|
|
|
if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(tickSource))
|
2019-07-14 16:50:11 -04:00
|
|
|
|
{
|
2022-05-31 15:29:35 -04:00
|
|
|
|
result = _networkSystemClockCore.GetClockContext(tickSource, out SystemClockContext context);
|
2019-07-14 16:50:11 -04:00
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
2019-10-07 23:48:49 -04:00
|
|
|
|
_localSystemClockCore.SetClockContext(context);
|
2019-07-14 16:50:11 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 23:48:49 -04:00
|
|
|
|
internal void CreateAutomaticCorrectionEvent(Horizon system)
|
|
|
|
|
{
|
2020-05-03 23:41:29 -04:00
|
|
|
|
_autoCorrectionEvent = new KEvent(system.KernelContext);
|
2019-10-07 23:48:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 15:29:35 -04:00
|
|
|
|
public ResultCode SetAutomaticCorrectionEnabled(ITickSource tickSource, bool autoCorrectionEnabled)
|
2019-07-14 16:50:11 -04:00
|
|
|
|
{
|
2022-05-31 15:29:35 -04:00
|
|
|
|
ResultCode result = ApplyAutomaticCorrection(tickSource, autoCorrectionEnabled);
|
2019-07-14 16:50:11 -04:00
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
_autoCorrectionEnabled = autoCorrectionEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsAutomaticCorrectionEnabled()
|
|
|
|
|
{
|
|
|
|
|
return _autoCorrectionEnabled;
|
|
|
|
|
}
|
2019-10-07 23:48:49 -04:00
|
|
|
|
|
|
|
|
|
public KReadableEvent GetAutomaticCorrectionReadableEvent()
|
|
|
|
|
{
|
|
|
|
|
return _autoCorrectionEvent.ReadableEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetAutomaticCorrectionUpdatedTime(SteadyClockTimePoint steadyClockTimePoint)
|
|
|
|
|
{
|
|
|
|
|
_autoCorrectionTime = steadyClockTimePoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SteadyClockTimePoint GetAutomaticCorrectionUpdatedTime()
|
|
|
|
|
{
|
|
|
|
|
return _autoCorrectionTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SignalAutomaticCorrectionEvent()
|
|
|
|
|
{
|
|
|
|
|
_autoCorrectionEvent.WritableEvent.Signal();
|
|
|
|
|
}
|
2019-07-14 16:50:11 -04:00
|
|
|
|
}
|
|
|
|
|
}
|