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.size() == 0)
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 public void post(
final Runnable runnable) {
39 synchronized (m_qtThread) {
40 m_pendingRunnables.add(runnable);
45 public void sleep(
int milliseconds) {
47 m_qtThread.sleep(milliseconds);
48 }
catch (InterruptedException e) {
53 public 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) {
void acquire(int n=1)
Tries to acquire n resources guarded by the semaphore.
void release(int n=1)
Releases n resources guarded by the semaphore.