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