mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-26 04:39:17 +08:00
d43edc865a
* Fix Gen5 thread and AGC compatibility * Trim compatibility comments * Report selected Vulkan GPU * Clean up CPU title label * Improve emulator frame pacing and performance * Regenerate package locks with pinned SDK --------- Co-authored-by: Spooks4576 <Spooks4576@users.noreply.github.com>
47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
// Copyright (C) 2026 SharpEmu Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.Versioning;
|
|
|
|
namespace SharpEmu.Libs;
|
|
|
|
public static class HostTimerResolution
|
|
{
|
|
private const uint TargetPeriodMilliseconds = 1;
|
|
|
|
private static int _requested;
|
|
|
|
public static void Request()
|
|
{
|
|
if (Interlocked.Exchange(ref _requested, 1) != 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!OperatingSystem.IsWindows())
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
if (TimeBeginPeriod(TargetPeriodMilliseconds) != 0)
|
|
{
|
|
Console.Error.WriteLine(
|
|
"[LOADER][WARN] Host timer resolution request rejected; " +
|
|
"timed waits keep the default ~15.6 ms granularity.");
|
|
}
|
|
}
|
|
catch (DllNotFoundException exception)
|
|
{
|
|
Console.Error.WriteLine(
|
|
$"[LOADER][WARN] Host timer resolution unavailable: {exception.Message}");
|
|
}
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[DllImport("winmm.dll", EntryPoint = "timeBeginPeriod", ExactSpelling = true)]
|
|
private static extern uint TimeBeginPeriod(uint uPeriod);
|
|
}
|