1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Removed high resolution timer counter

This commit is contained in:
Darth Affe 2022-05-07 16:00:23 +02:00
parent 02d6f4e53e
commit d555406722

View File

@ -28,7 +28,6 @@ public static class TimerHelper
private static readonly object HIGH_RESOLUTION_TIMER_LOCK = new(); private static readonly object HIGH_RESOLUTION_TIMER_LOCK = new();
private static bool _areHighResolutionTimersEnabled = false; private static bool _areHighResolutionTimersEnabled = false;
private static int _highResolutionTimerUsers = 0;
private static bool _useHighResolutionTimers = true; private static bool _useHighResolutionTimers = true;
/// <summary> /// <summary>
@ -93,20 +92,19 @@ public static class TimerHelper
/// <returns>A disposable to remove the request.</returns> /// <returns>A disposable to remove the request.</returns>
public static IDisposable RequestHighResolutionTimer() public static IDisposable RequestHighResolutionTimer()
{ {
HighResolutionTimerDisposable timerLease = new();
lock (HIGH_RESOLUTION_TIMER_LOCK) lock (HIGH_RESOLUTION_TIMER_LOCK)
{ {
_highResolutionTimerUsers++; _timerLeases.Add(timerLease);
CheckHighResolutionTimerUsage(); CheckHighResolutionTimerUsage();
} }
HighResolutionTimerDisposable timerLease = new();
_timerLeases.Add(timerLease);
return timerLease; return timerLease;
} }
private static void CheckHighResolutionTimerUsage() private static void CheckHighResolutionTimerUsage()
{ {
if (UseHighResolutionTimers && (_highResolutionTimerUsers > 0)) if (UseHighResolutionTimers && (_timerLeases.Count > 0))
EnableHighResolutionTimers(); EnableHighResolutionTimers();
else else
DisableHighResolutionTimers(); DisableHighResolutionTimers();
@ -146,7 +144,7 @@ public static class TimerHelper
/// </summary> /// </summary>
public static void DisposeAllHighResolutionTimerRequests() public static void DisposeAllHighResolutionTimerRequests()
{ {
List<HighResolutionTimerDisposable> timerLeases = _timerLeases.ToList(); List<HighResolutionTimerDisposable> timerLeases = new(_timerLeases);
foreach (HighResolutionTimerDisposable timer in timerLeases) foreach (HighResolutionTimerDisposable timer in timerLeases)
timer.Dispose(); timer.Dispose();
} }
@ -172,7 +170,6 @@ public static class TimerHelper
lock (HIGH_RESOLUTION_TIMER_LOCK) lock (HIGH_RESOLUTION_TIMER_LOCK)
{ {
_timerLeases.Remove(this); _timerLeases.Remove(this);
_highResolutionTimerUsers--;
CheckHighResolutionTimerUsage(); CheckHighResolutionTimerUsage();
} }
} }