Browse Source

Added IDispatcherImplWithExplicitBackgroundProcessing to EpollDispatcherImpl. (#21152)

pull/21168/head
Nikita Tsukanov 5 months ago
committed by GitHub
parent
commit
b7e95c2b09
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 32
      src/Linux/Avalonia.LinuxFramebuffer/EpollDispatcherImpl.cs

32
src/Linux/Avalonia.LinuxFramebuffer/EpollDispatcherImpl.cs

@ -8,7 +8,7 @@ using Avalonia.Threading;
namespace Avalonia.LinuxFramebuffer;
internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl
internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl, IDispatcherImplWithExplicitBackgroundProcessing
{
private readonly ManagedDispatcherImpl.IManagedDispatcherInputProvider _inputProvider;
private readonly Thread _mainThread;
@ -88,6 +88,7 @@ internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl
private TimeSpan? _nextTimer;
private int _epoll;
private Stopwatch _clock = Stopwatch.StartNew();
private bool _backgroundProcessingRequested;
public EpollDispatcherImpl(ManagedDispatcherImpl.IManagedDispatcherInputProvider inputProvider)
{
@ -151,6 +152,19 @@ internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl
continue;
}
bool triggerBackgroundProcessing;
lock (_lock)
{
triggerBackgroundProcessing = _backgroundProcessingRequested;
_backgroundProcessingRequested = false;
}
if (triggerBackgroundProcessing)
{
ReadyForBackgroundProcessing?.Invoke();
continue;
}
epoll_event ev;
if (_nextTimer != null)
@ -235,4 +249,20 @@ internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl
public bool CanQueryPendingInput => true;
public bool HasPendingInput => _inputProvider.HasInput;
private Action? ReadyForBackgroundProcessing { get; set; }
event Action? IDispatcherImplWithExplicitBackgroundProcessing.ReadyForBackgroundProcessing
{
add => ReadyForBackgroundProcessing += value;
remove => ReadyForBackgroundProcessing -= value;
}
void IDispatcherImplWithExplicitBackgroundProcessing.RequestBackgroundProcessing()
{
lock (_lock)
{
_backgroundProcessingRequested = true;
Wakeup();
}
}
}

Loading…
Cancel
Save