Browse Source

Added IDispatcherImplWithExplicitBackgroundProcessing to EpollDispatcherImpl. (#21152)

release/12.0.1
Nikita Tsukanov 6 months ago
committed by Julien Lebosquain
parent
commit
561dbc1f3b
  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; namespace Avalonia.LinuxFramebuffer;
internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl, IDispatcherImplWithExplicitBackgroundProcessing
{ {
private readonly ManagedDispatcherImpl.IManagedDispatcherInputProvider _inputProvider; private readonly ManagedDispatcherImpl.IManagedDispatcherInputProvider _inputProvider;
private readonly Thread _mainThread; private readonly Thread _mainThread;
@ -88,6 +88,7 @@ internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl
private TimeSpan? _nextTimer; private TimeSpan? _nextTimer;
private int _epoll; private int _epoll;
private Stopwatch _clock = Stopwatch.StartNew(); private Stopwatch _clock = Stopwatch.StartNew();
private bool _backgroundProcessingRequested;
public EpollDispatcherImpl(ManagedDispatcherImpl.IManagedDispatcherInputProvider inputProvider) public EpollDispatcherImpl(ManagedDispatcherImpl.IManagedDispatcherInputProvider inputProvider)
{ {
@ -151,6 +152,19 @@ internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl
continue; continue;
} }
bool triggerBackgroundProcessing;
lock (_lock)
{
triggerBackgroundProcessing = _backgroundProcessingRequested;
_backgroundProcessingRequested = false;
}
if (triggerBackgroundProcessing)
{
ReadyForBackgroundProcessing?.Invoke();
continue;
}
epoll_event ev; epoll_event ev;
if (_nextTimer != null) if (_nextTimer != null)
@ -235,4 +249,20 @@ internal unsafe class EpollDispatcherImpl : IControlledDispatcherImpl
public bool CanQueryPendingInput => true; public bool CanQueryPendingInput => true;
public bool HasPendingInput => _inputProvider.HasInput; 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