23 changed files with 161 additions and 156 deletions
@ -1,60 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Threading |
|||
{ |
|||
public class SingleThreadDispatcher : Dispatcher |
|||
{ |
|||
class ThreadingInterface : IPlatformThreadingInterface |
|||
{ |
|||
private readonly AutoResetEvent _evnt = new AutoResetEvent(false); |
|||
private readonly JobRunner _timerJobRunner; |
|||
|
|||
public ThreadingInterface() |
|||
{ |
|||
_timerJobRunner = new JobRunner(this); |
|||
} |
|||
|
|||
public void RunLoop(CancellationToken cancellationToken) |
|||
{ |
|||
while (!cancellationToken.IsCancellationRequested) |
|||
{ |
|||
_evnt.WaitOne(); |
|||
if (cancellationToken.IsCancellationRequested) |
|||
return; |
|||
Signaled?.Invoke(); |
|||
_timerJobRunner.RunJobs(); |
|||
} |
|||
} |
|||
|
|||
public IDisposable StartTimer(TimeSpan interval, Action tick) |
|||
=> AvaloniaLocator.Current.GetService<IRuntimePlatform>().StartSystemTimer(interval, |
|||
() => _timerJobRunner.Post(tick, DispatcherPriority.Normal)); |
|||
|
|||
public void Signal() => _evnt.Set(); |
|||
//TODO: Actually perform a check
|
|||
public bool CurrentThreadIsLoopThread => true; |
|||
|
|||
public event Action Signaled; |
|||
} |
|||
|
|||
public SingleThreadDispatcher() : base(new ThreadingInterface()) |
|||
{ |
|||
} |
|||
|
|||
public static Dispatcher StartNew(CancellationToken token) |
|||
{ |
|||
var dispatcher = new SingleThreadDispatcher(); |
|||
AvaloniaLocator.Current.GetService<IRuntimePlatform>().PostThreadPoolItem(() => |
|||
{ |
|||
dispatcher.MainLoop(token); |
|||
}); |
|||
return dispatcher; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Avalonia.Threading; |
|||
|
|||
namespace Avalonia.Gtk3.Interop |
|||
{ |
|||
static class GlibPriority |
|||
{ |
|||
public static int High = -100; |
|||
public static int Default = 0; |
|||
public static int HighIdle = 100; |
|||
public static int GtkResize = HighIdle + 10; |
|||
public static int GtkPaint = HighIdle + 20; |
|||
public static int DefaultIdle = 200; |
|||
public static int Low = 300; |
|||
public static int GdkEvents = Default; |
|||
public static int GdkRedraw = HighIdle + 20; |
|||
|
|||
public static int FromDispatcherPriority(DispatcherPriority prio) |
|||
{ |
|||
if (prio == DispatcherPriority.Send) |
|||
return High; |
|||
if (prio == DispatcherPriority.Normal) |
|||
return Default - 4; |
|||
if (prio == DispatcherPriority.DataBind) |
|||
return Default - 3; |
|||
if (prio == DispatcherPriority.Render) |
|||
return Default -2; |
|||
if (prio == DispatcherPriority.Loaded) |
|||
return Default - 1; |
|||
if (prio == DispatcherPriority.Input) |
|||
return Default; |
|||
if (prio == DispatcherPriority.Background) |
|||
return DefaultIdle; |
|||
if (prio == DispatcherPriority.ContextIdle) |
|||
return DefaultIdle + 100; |
|||
if (prio == DispatcherPriority.ApplicationIdle) |
|||
return DefaultIdle + 200; |
|||
if (prio == DispatcherPriority.SystemIdle) |
|||
return DefaultIdle + 200; |
|||
throw new ArgumentException("Unknown priority"); |
|||
|
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue