diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index cc79324096..8b64856621 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -116,6 +116,8 @@ Q_CONSTINIT QEventDispatcherWasm *QEventDispatcherWasm::g_mainThreadEventDispatc #if QT_CONFIG(thread) Q_CONSTINIT QVector QEventDispatcherWasm::g_secondaryThreadEventDispatchers; Q_CONSTINIT std::mutex QEventDispatcherWasm::g_staticDataMutex; +emscripten::ProxyingQueue QEventDispatcherWasm::g_proxyingQueue; +pthread_t QEventDispatcherWasm::g_mainThread; #endif // ### dynamic initialization: std::multimap QEventDispatcherWasm::g_socketNotifiers; @@ -144,6 +146,9 @@ QEventDispatcherWasm::QEventDispatcherWasm() // dispatchers so we set a global pointer to it. Q_ASSERT(g_mainThreadEventDispatcher == nullptr); g_mainThreadEventDispatcher = this; +#if QT_CONFIG(thread) + g_mainThread = pthread_self(); +#endif } else { #if QT_CONFIG(thread) std::lock_guard lock(g_staticDataMutex); @@ -818,7 +823,9 @@ void QEventDispatcherWasm::runOnMainThread(std::function fn) #if QT_CONFIG(thread) if (!emscripten_is_main_runtime_thread()) { void *context = new std::function(fn); - emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, reinterpret_cast(trampoline), context); + g_proxyingQueue.proxyAsync(g_mainThread, [context]{ + trampoline(context); + }); return; } #endif @@ -832,7 +839,9 @@ void QEventDispatcherWasm::runOnMainThreadAsync(std::function fn) void *context = new std::function(fn); #if QT_CONFIG(thread) if (!emscripten_is_main_runtime_thread()) { - emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, reinterpret_cast(trampoline), context); + g_proxyingQueue.proxyAsync(g_mainThread, [context]{ + trampoline(context); + }); return; } #endif diff --git a/src/corelib/kernel/qeventdispatcher_wasm_p.h b/src/corelib/kernel/qeventdispatcher_wasm_p.h index 50f1bda2b2..f253a1a95f 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm_p.h +++ b/src/corelib/kernel/qeventdispatcher_wasm_p.h @@ -24,6 +24,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher); @@ -106,6 +108,8 @@ private: static QVector g_secondaryThreadEventDispatchers; static std::mutex g_staticDataMutex; + static emscripten::ProxyingQueue g_proxyingQueue; + static pthread_t g_mainThread; // Note on mutex usage: the global g_staticDataMutex protects the global (g_ prefixed) data, // while the per eventdispatcher m_mutex protects the state accociated with blocking and waking