// Copyright (C) 2024 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QWASMGLOBAL_P_H #define QWASMGLOBAL_P_H #include #include // // W A R N I N G // ------------- // // This file is not part of the Qt API. It exists purely as an // implementation detail. This header file may change from version to // version without notice, or even be removed. // // We mean it. // QT_BEGIN_NAMESPACE namespace qwasmglobal { #if QT_CONFIG(thread) template T proxyCall(std::function task, emscripten::ProxyingQueue *queue) { T result; queue->proxySync(emscripten_main_runtime_thread_id(), [task, result = &result]() { *result = task(); }); return result; } template<> inline void proxyCall(std::function task, emscripten::ProxyingQueue *queue) { queue->proxySync(emscripten_main_runtime_thread_id(), task); } template T runTaskOnMainThread(std::function task, emscripten::ProxyingQueue *queue) { return emscripten_is_main_runtime_thread() ? task() : proxyCall(std::move(task), queue); } template T runTaskOnMainThread(std::function task) { emscripten::ProxyingQueue singleUseQueue; return runTaskOnMainThread(task, &singleUseQueue); } #else template T runTaskOnMainThread(std::function task) { return task(); } #endif // QT_CONFIG(thread) Q_CORE_EXPORT void runAsync(std::function fn); Q_CORE_EXPORT void runOnMainThread(std::function fn); Q_CORE_EXPORT void runOnMainThreadAsync(std::function fn); } QT_END_NAMESPACE #endif // QWASMGLOBAL_P_H