Browse Source
Merge pull request #8691 from AvaloniaUI/android-current-thread-perf
Optimize CurrentThreadIsLoopThread on android backend
pull/8692/head
Max Katz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
20 additions and
1 deletions
-
src/Android/Avalonia.Android/AndroidThreadingInterface.cs
|
|
|
@ -14,6 +14,7 @@ namespace Avalonia.Android |
|
|
|
internal sealed class AndroidThreadingInterface : IPlatformThreadingInterface |
|
|
|
{ |
|
|
|
private Handler _handler; |
|
|
|
private static Thread s_uiThread; |
|
|
|
|
|
|
|
public AndroidThreadingInterface() |
|
|
|
{ |
|
|
|
@ -76,7 +77,25 @@ namespace Avalonia.Android |
|
|
|
EnsureInvokeOnMainThread(() => Signaled?.Invoke(null)); |
|
|
|
} |
|
|
|
|
|
|
|
public bool CurrentThreadIsLoopThread => Looper.MainLooper.Thread.Equals(Java.Lang.Thread.CurrentThread()); |
|
|
|
public bool CurrentThreadIsLoopThread |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
if (s_uiThread != null) |
|
|
|
return s_uiThread == Thread.CurrentThread; |
|
|
|
|
|
|
|
var isOnMainThread = OperatingSystem.IsAndroidVersionAtLeast(23) |
|
|
|
? Looper.MainLooper.IsCurrentThread |
|
|
|
: Looper.MainLooper.Thread.Equals(Java.Lang.Thread.CurrentThread()); |
|
|
|
if (isOnMainThread) |
|
|
|
{ |
|
|
|
s_uiThread = Thread.CurrentThread; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
public event Action<DispatcherPriority?> Signaled; |
|
|
|
} |
|
|
|
} |
|
|
|
|