Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwasmglobal.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
<
QtCore
/
qglobalstatic
.
h
>
5
#
include
"qwasmglobal_p.h"
6
7
namespace
qwasmglobal
{
8
9
Q_GLOBAL_STATIC
(
emscripten
::
ProxyingQueue
,
proxyingQueue
);
10
11
namespace
{
12
void
trampoline(
void
*context) {
13
14
auto
async_fn = [](
void
*context){
15
std::function<
void
(
void
)> *fn =
reinterpret_cast
<std::function<
void
(
void
)> *>(context);
16
(*fn)();
17
delete
fn;
18
};
19
20
emscripten_async_call(async_fn, context, 0);
21
}
22
}
23
24
void
runOnMainThread
(
std
::
function
<
void
(
void
)>
fn
)
25
{
26
#
if
QT_CONFIG
(
thread
)
27
runTaskOnMainThread
<
void
>(
fn
,
proxyingQueue
());
28
#
else
29
runTaskOnMainThread
<
void
>(
fn
);
30
#
endif
31
}
32
33
// Runs a function asynchronously. Main thread only.
34
void
runAsync
(
std
::
function
<
void
(
void
)>
fn
)
35
{
36
Q_ASSERT
(
emscripten_is_main_runtime_thread
());
37
trampoline
(
new
std
::
function
<
void
(
void
)>(
fn
));
38
}
39
40
// Runs a function on the main thread. The function always runs asynchronously,
41
// also if the calling thread is the main thread.
42
void
runOnMainThreadAsync
(
std
::
function
<
void
(
void
)>
fn
)
43
{
44
void
*
context
=
new
std
::
function
<
void
(
void
)>(
fn
);
45
#
if
QT_CONFIG
(
thread
)
46
if
(!
emscripten_is_main_runtime_thread
()) {
47
proxyingQueue
()->
proxyAsync
(
emscripten_main_runtime_thread_id
(), [
context
]{
48
trampoline
(
context
);
49
});
50
return
;
51
}
52
#
endif
53
trampoline
(
context
);
54
}
55
56
}
qwasmglobal
Definition
qwasmglobal.cpp:7
qwasmglobal::runOnMainThreadAsync
void runOnMainThreadAsync(std::function< void(void)> fn)
Definition
qwasmglobal.cpp:42
qwasmglobal::runAsync
void runAsync(std::function< void(void)> fn)
Definition
qwasmglobal.cpp:34
qwasmglobal::runOnMainThread
void runOnMainThread(std::function< void(void)> fn)
Definition
qwasmglobal.cpp:24
qtbase
src
corelib
platform
wasm
qwasmglobal.cpp
Generated on
for Qt by
1.14.0