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>
7
8namespace qwasmglobal {
9
11
12namespace {
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
25void runOnMainThread(std::function<void(void)> fn)
26{
27#if QT_CONFIG(thread)
29#else
31#endif
32}
33
34// Runs a function asynchronously. Main thread only.
35void runAsync(std::function<void(void)> fn)
36{
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.
44{
45 void *context = new std::function<void(void)>(fn);
46#if QT_CONFIG(thread)
50 });
51 return;
52 }
53#endif
55}
56
57}
void runOnMainThreadAsync(std::function< void(void)> fn)
void runAsync(std::function< void(void)> fn)
void runOnMainThread(std::function< void(void)> fn)