From 3d1e257770e8c79c7cd9a08f9caf1bd8395cb10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 31 Oct 2019 09:33:40 +0100 Subject: Wasm: Support event loop wakeup from secondary threads Minimal fix for the missing wakeup issue, in leu of a new event loop implementation. So far, emscripten_async_run_in_main_runtime_thread_ looks to be our option for scheduling calls on the main thread. This function is available on emsdk 1.38.22 and higher. Requires making from QEventDispatcherUNIX::wakeUp() non-final. The future event dispatcher implementation will not inherit QEventDispatcherUNIX, so this is a temporary change. Fixes: QTBUG-75793 Task-number: QTBUG-76007 Change-Id: Ie6f6ee6f7674206fc0673a4fe866ac614432ab65 Reviewed-by: Lorn Potter --- .../platforms/wasm/qwasmeventdispatcher.cpp | 23 ++++++++++++++++++++++ src/plugins/platforms/wasm/qwasmeventdispatcher.h | 2 ++ 2 files changed, 25 insertions(+) (limited to 'src/plugins/platforms/wasm') diff --git a/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp b/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp index 41355d72ae..d89cd78b28 100644 --- a/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp +++ b/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp @@ -33,6 +33,14 @@ #include +#if (__EMSCRIPTEN_major__ > 1 || __EMSCRIPTEN_minor__ > 38 || __EMSCRIPTEN_minor__ == 38 && __EMSCRIPTEN_tiny__ >= 22) +# define EMSCRIPTEN_HAS_ASYNC_RUN_IN_MAIN_RUNTIME_THREAD +#endif + +#ifdef EMSCRIPTEN_HAS_ASYNC_RUN_IN_MAIN_RUNTIME_THREAD +#include +#endif + class QWasmEventDispatcherPrivate : public QEventDispatcherUNIXPrivate { @@ -179,3 +187,18 @@ void QWasmEventDispatcher::doMaintainTimers() emscripten_async_call(callback, this, toWaitDuration); m_currentTargetTime = newTargetTime; } + +void QWasmEventDispatcher::wakeUp() +{ +#ifdef EMSCRIPTEN_HAS_ASYNC_RUN_IN_MAIN_RUNTIME_THREAD + if (!emscripten_is_main_runtime_thread()) + emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, (void*)(&QWasmEventDispatcher::mainThreadWakeUp), this); +#endif + QEventDispatcherUNIX::wakeUp(); +} + +void QWasmEventDispatcher::mainThreadWakeUp(void *eventDispatcher) +{ + emscripten_resume_main_loop(); // Service possible requestUpdate Calls + static_cast(eventDispatcher)->processEvents(QEventLoop::AllEvents); +} diff --git a/src/plugins/platforms/wasm/qwasmeventdispatcher.h b/src/plugins/platforms/wasm/qwasmeventdispatcher.h index 5300b3de73..f72d92ce07 100644 --- a/src/plugins/platforms/wasm/qwasmeventdispatcher.h +++ b/src/plugins/platforms/wasm/qwasmeventdispatcher.h @@ -51,6 +51,8 @@ public: protected: bool processEvents(QEventLoop::ProcessEventsFlags flags) override; void doMaintainTimers(); + void wakeUp() override; + static void mainThreadWakeUp(void *eventDispatcher); private: bool m_hasMainLoop = false; -- cgit v1.2.3