Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
QtThread.java
Go to the documentation of this file.
1
// Copyright (C) 2018 BogDan Vatra <bogdan@kdab.com>
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
package
org.qtproject.qt.android;
5
6
import
java.util.ArrayList;
7
import
java.util.concurrent.Semaphore;
8
9
class
QtThread {
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() {
13
@
Override
14
public
void
run() {
15
while
(!m_exit) {
16
try
{
17
ArrayList<Runnable> pendingRunnables;
18
synchronized
(m_qtThread) {
19
if
(m_pendingRunnables.isEmpty())
20
m_qtThread.wait();
21
pendingRunnables =
new
ArrayList<>(m_pendingRunnables);
22
m_pendingRunnables.clear();
23
}
24
for
(Runnable runnable : pendingRunnables)
25
runnable.run();
26
}
catch
(InterruptedException e) {
27
e.printStackTrace();
28
}
29
}
30
}
31
});
32
33
QtThread() {
34
m_qtThread.setName(
"qtMainLoopThread"
);
35
m_qtThread.start();
36
}
37
38
void
post(
final
Runnable runnable) {
39
synchronized
(m_qtThread) {
40
m_pendingRunnables.add(runnable);
41
m_qtThread.notify();
42
}
43
}
44
45
void
sleep(
int
milliseconds) {
46
try
{
47
Thread.sleep(milliseconds);
48
}
catch
(InterruptedException e) {
49
e.printStackTrace();
50
}
51
}
52
53
void
run(
final
Runnable runnable) {
54
final
Semaphore sem =
new
Semaphore(0);
55
synchronized
(m_qtThread) {
56
m_pendingRunnables.add(() -> {
57
runnable.run();
58
sem.release();
59
});
60
m_qtThread.notify();
61
}
62
try
{
63
sem.acquire();
64
}
catch
(InterruptedException e) {
65
e.printStackTrace();
66
}
67
}
68
69
void
exit()
70
{
71
m_exit =
true
;
72
synchronized
(m_qtThread) {
73
m_qtThread.notify();
74
}
75
try
{
76
m_qtThread.join();
77
}
catch
(InterruptedException e) {
78
e.printStackTrace();
79
}
80
}
81
82
boolean
isAlive()
83
{
84
return
m_qtThread.isAlive();
85
}
86
}
QtMocConstants::Override
@ Override
Definition
qtmocconstants.h:43
qtbase
src
android
jar
src
org
qtproject
qt
android
QtThread.java
Generated on
for Qt by
1.18.0