Browse Source

Removed custom win32 render timer since it leaks pool threads

vnext
Nikita Tsukanov 7 years ago
parent
commit
bca3b42a0c
  1. 56
      src/Windows/Avalonia.Win32/RenderTimer.cs
  2. 2
      src/Windows/Avalonia.Win32/Win32Platform.cs

56
src/Windows/Avalonia.Win32/RenderTimer.cs

@ -1,56 +0,0 @@
using System;
using System.Reactive.Disposables;
using System.Threading;
using Avalonia.Rendering;
using Avalonia.Win32.Interop;
namespace Avalonia.Win32
{
internal class RenderTimer : DefaultRenderTimer
{
private UnmanagedMethods.WaitOrTimerCallback timerDelegate;
private static IntPtr _timerQueue;
private static void EnsureTimerQueueCreated()
{
if (Volatile.Read(ref _timerQueue) == null)
{
var queue = UnmanagedMethods.CreateTimerQueue();
if (Interlocked.CompareExchange(ref _timerQueue, queue, IntPtr.Zero) != IntPtr.Zero)
{
UnmanagedMethods.DeleteTimerQueueEx(queue, IntPtr.Zero);
}
}
}
public RenderTimer(int framesPerSecond)
: base(framesPerSecond)
{
}
protected override IDisposable StartCore(Action<TimeSpan> tick)
{
EnsureTimerQueueCreated();
var msPerFrame = 1000 / FramesPerSecond;
timerDelegate = (_, __) => tick(TimeSpan.FromMilliseconds(Environment.TickCount));
UnmanagedMethods.CreateTimerQueueTimer(
out var timer,
_timerQueue,
timerDelegate,
IntPtr.Zero,
(uint)msPerFrame,
(uint)msPerFrame,
0
);
return Disposable.Create(() =>
{
timerDelegate = null;
UnmanagedMethods.DeleteTimerQueueTimer(_timerQueue, timer, IntPtr.Zero);
});
}
}
}

2
src/Windows/Avalonia.Win32/Win32Platform.cs

@ -86,7 +86,7 @@ namespace Avalonia.Win32
.Bind<IPlatformSettings>().ToConstant(s_instance)
.Bind<IPlatformThreadingInterface>().ToConstant(s_instance)
.Bind<IRenderLoop>().ToConstant(new RenderLoop())
.Bind<IRenderTimer>().ToConstant(new RenderTimer(60))
.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
.Bind<ISystemDialogImpl>().ToSingleton<SystemDialogImpl>()
.Bind<IWindowingPlatform>().ToConstant(s_instance)
.Bind<PlatformHotkeyConfiguration>().ToSingleton<PlatformHotkeyConfiguration>()

Loading…
Cancel
Save