4package org.qtproject.qt.android;
6import java.util.ArrayList;
7import java.util.concurrent.Semaphore;
10 private final ArrayList<Runnable> m_pendingRunnables =
new ArrayList<>();
11 private boolean m_exit =
false;
12 private final Thread m_qtThread =
new Thread(
new Runnable() {
17 ArrayList<Runnable> pendingRunnables;
18 synchronized (m_qtThread) {
19 if (m_pendingRunnables.isEmpty())
21 pendingRunnables =
new ArrayList<>(m_pendingRunnables);
22 m_pendingRunnables.clear();
24 for (Runnable runnable : pendingRunnables)
26 }
catch (InterruptedException e) {
34 m_qtThread.setName(
"qtMainLoopThread");
38 void post(
final Runnable runnable) {
39 synchronized (m_qtThread) {
40 m_pendingRunnables.add(runnable);
45 void sleep(
int milliseconds) {
47 Thread.sleep(milliseconds);
48 }
catch (InterruptedException e) {
53 void run(
final Runnable runnable) {
54 final Semaphore sem =
new Semaphore(0);
55 synchronized (m_qtThread) {
56 m_pendingRunnables.add(() -> {
64 }
catch (InterruptedException e) {
72 synchronized (m_qtThread) {
77 }
catch (InterruptedException e) {
84 return m_qtThread.isAlive();