XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
namespace XFESystem.NativeKernel;

// Pure arithmetic shared by the hardware timer and host checks. A requested
// sleep duration cannot be more precise than the actual interrupt period.
public static class TimerCalibration
{
    public const ulong DesktopPeriodNanoseconds = 1000000;
    public static bool TryInitialCount(uint elapsedCounts, ulong elapsedNanoseconds, ulong periodNanoseconds, out uint initialCount)
    {
        initialCount = 0;
        if (elapsedCounts == 0 || elapsedNanoseconds == 0 || periodNanoseconds == 0 || periodNanoseconds > 1000000000) return false;
        ulong result = (ulong)elapsedCounts * periodNanoseconds / elapsedNanoseconds;
        if (result == 0 || result > 0xffffffff) return false;
        initialCount = (uint)result;
        return true;
    }
}