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>
6
7namespace qwasmglobal {
8
10
11namespace {
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
24void runOnMainThread(std::function<void(void)> fn)
25{
26#if QT_CONFIG(thread)
28#else
30#endif
31}
32
33// Runs a function asynchronously. Main thread only.
34void runAsync(std::function<void(void)> fn)
35{
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.
43{
44 void *context = new std::function<void(void)>(fn);
45#if QT_CONFIG(thread)
49 });
50 return;
51 }
52#endif
54}
55
56}
void runOnMainThreadAsync(std::function< void(void)> fn)
void runAsync(std::function< void(void)> fn)
void runOnMainThread(std::function< void(void)> fn)