2019-07-14 22:50:11 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 05:48:49 +02:00
|
|
|
|
public override ResultCode GetClockContext(KThread thread, out SystemClockContext context)
|
2019-07-14 22:50:11 +02:00
|
|
|
|
{
|
|
|
|
|
ResultCode result = ApplyAutomaticCorrection(thread, false);
|
|
|
|
|
|
|
|
|
|
context = new SystemClockContext();
|
|
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
|
{
|
2019-10-08 05:48:49 +02:00
|
|
|
|
return _localSystemClockCore.GetClockContext(thread, 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ResultCode ApplyAutomaticCorrection(KThread thread, bool autoCorrectionEnabled)
|
|
|
|
|
{
|
|
|
|
|
ResultCode result = ResultCode.Success;
|
|
|
|
|
|
|
|
|
|
if (_autoCorrectionEnabled != autoCorrectionEnabled && _networkSystemClockCore.IsClockSetup(thread))
|
|
|
|
|
{
|
2019-10-08 05:48:49 +02:00
|
|
|
|
result = _networkSystemClockCore.GetClockContext(thread, 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
|
|
|
|
}
|
|
|
|
|
|
2019-07-14 22:50:11 +02:00
|
|
|
|
public ResultCode SetAutomaticCorrectionEnabled(KThread thread, bool autoCorrectionEnabled)
|
|
|
|
|
{
|
|
|
|
|
ResultCode result = ApplyAutomaticCorrection(thread, autoCorrectionEnabled);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|