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