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
// Qt-Security score:significant reason:default
4
5
#
include
<
QtCore
/
qglobalstatic
.
h
>
6
#
include
"qwasmglobal_p.h"
7
8
namespace
qwasmglobal
{
9
10
Q_GLOBAL_STATIC
(
emscripten
::
ProxyingQueue
,
proxyingQueue
);
11
12
namespace
{
13
void
trampoline(
void
*context) {
14
15
auto
async_fn = [](
void
*context){
16
std::function<
void
(
void
)> *fn =
reinterpret_cast
<std::function<
void
(
void
)> *>(context);
17
(*fn)();
18
delete
fn;
19
};
20
21
emscripten_async_call(async_fn, context, 0);
22
}
23
}
24
25
void
runOnMainThread
(
std
::
function
<
void
(
void
)>
fn
)
26
{
27
#
if
QT_CONFIG
(
thread
)
28
runTaskOnMainThread
<
void
>(
fn
,
proxyingQueue
());
29
#
else
30
runTaskOnMainThread
<
void
>(
fn
);
31
#
endif
32
}
33
34
// Runs a function asynchronously. Main thread only.
35
void
runAsync
(
std
::
function
<
void
(
void
)>
fn
)
36
{
37
Q_ASSERT
(
emscripten_is_main_runtime_thread
());
38
trampoline
(
new
std
::
function
<
void
(
void
)>(
fn
));
39
}
40
41
// Runs a function on the main thread. The function always runs asynchronously,
42
// also if the calling thread is the main thread.
43
void
runOnMainThreadAsync
(
std
::
function
<
void
(
void
)>
fn
)
44
{
45
void
*
context
=
new
std
::
function
<
void
(
void
)>(
fn
);
46
#
if
QT_CONFIG
(
thread
)
47
if
(!
emscripten_is_main_runtime_thread
()) {
48
proxyingQueue
()->
proxyAsync
(
emscripten_main_runtime_thread_id
(), [
context
]{
49
trampoline
(
context
);
50
});
51
return
;
52
}
53
#
endif
54
trampoline
(
context
);
55
}
56
57
}
qwasmglobal
Definition
qwasmglobal.cpp:8
qwasmglobal::runOnMainThreadAsync
void runOnMainThreadAsync(std::function< void(void)> fn)
Definition
qwasmglobal.cpp:43
qwasmglobal::runAsync
void runAsync(std::function< void(void)> fn)
Definition
qwasmglobal.cpp:35
qwasmglobal::runOnMainThread
void runOnMainThread(std::function< void(void)> fn)
Definition
qwasmglobal.cpp:25
qtbase
src
corelib
platform
wasm
qwasmglobal.cpp
Generated on
for Qt by
1.16.1