MessageQueue: integrate with glib main loop

Adds a special treatment for the main Looper to not block in java code,
but instead return to glib managed thread loop. Timeouts in the mainloop
are now handled using g_timeout_add_full().

Also defer Activity construction, so that every thing is set up properly
when the constructor runs.
This commit is contained in:
Julian Winkler
2023-08-08 10:16:17 +02:00
parent c6c4e8b3a2
commit 4491de7f63
7 changed files with 80 additions and 29 deletions

View File

@@ -50,7 +50,7 @@ public final class MessageQueue {
private native static long nativeInit();
private native static void nativeDestroy(long ptr);
private native static void nativePollOnce(long ptr, int timeoutMillis);
private native static boolean nativePollOnce(long ptr, int timeoutMillis);
private native static void nativeWake(long ptr);
private native static boolean nativeIsIdling(long ptr);
@@ -134,7 +134,9 @@ public final class MessageQueue {
// We can assume mPtr != 0 because the loop is obviously still running.
// The looper will not call this method after the loop quits.
nativePollOnce(mPtr, nextPollTimeoutMillis);
if (nativePollOnce(mPtr, nextPollTimeoutMillis)) {
return null; // thread is managed by glib, so return instead of blocking
}
synchronized (this) {
// Try to retrieve the next message. Return if found.