0
0
Fork 0
This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ryujinx-final/Ryujinx.HLE/HOS/Services/Time/Clock/StandardNetworkSystemClockCore.cs
Thomas Guillemard 1f3a34dd7a Implement time:* 2.0.0 & 3.0.0 commands (#735)
* Finish ISteadyClock implementation

* Implement IsStandardNetworkSystemClockAccuracySufficient

Also use signed values for offsets and TimeSpanType

* Address comments

* Fix one missing nit and improve one comment
2019-07-15 19:52:35 +02:00

82 lines
2.7 KiB
C#

using System;
using Ryujinx.HLE.HOS.Kernel.Threading;
namespace Ryujinx.HLE.HOS.Services.Time.Clock
{
class StandardNetworkSystemClockCore : SystemClockCore
{
private SteadyClockCore _steadyClockCore;
private SystemClockContext _context;
private TimeSpanType _standardNetworkClockSufficientAccuracy;
private static StandardNetworkSystemClockCore instance;
public static StandardNetworkSystemClockCore Instance
{
get
{
if (instance == null)
{
instance = new StandardNetworkSystemClockCore(SteadyClockCore.Instance);
}
return instance;
}
}
public StandardNetworkSystemClockCore(SteadyClockCore steadyClockCore)
{
_steadyClockCore = steadyClockCore;
_context = new SystemClockContext();
_context.SteadyTimePoint.ClockSourceId = steadyClockCore.GetClockSourceId();
_standardNetworkClockSufficientAccuracy = new TimeSpanType(0);
}
public override ResultCode Flush(SystemClockContext context)
{
// TODO: set:sys SetNetworkSystemClockContext
return ResultCode.Success;
}
public override SteadyClockCore GetSteadyClockCore()
{
return _steadyClockCore;
}
public override ResultCode GetSystemClockContext(KThread thread, out SystemClockContext context)
{
context = _context;
return ResultCode.Success;
}
public override ResultCode SetSystemClockContext(SystemClockContext context)
{
_context = context;
return ResultCode.Success;
}
public bool IsStandardNetworkSystemClockAccuracySufficient(KThread thread)
{
SteadyClockCore steadyClockCore = GetSteadyClockCore();
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(thread);
bool isStandardNetworkClockSufficientAccuracy = false;
if (_context.SteadyTimePoint.GetSpanBetween(currentTimePoint, out long outSpan) == ResultCode.Success)
{
isStandardNetworkClockSufficientAccuracy = outSpan * 1000000000 < _standardNetworkClockSufficientAccuracy.NanoSeconds;
}
return isStandardNetworkClockSufficientAccuracy;
}
public void SetStandardNetworkClockSufficientAccuracy(TimeSpanType standardNetworkClockSufficientAccuracy)
{
_standardNetworkClockSufficientAccuracy = standardNetworkClockSufficientAccuracy;
}
}
}