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 <lorn.potter@gmail.com>
This commit is contained in:
parent
2f536411d8
commit
3d1e257770
@ -118,7 +118,7 @@ public:
|
||||
|
||||
int remainingTime(int timerId) final;
|
||||
|
||||
void wakeUp() final;
|
||||
void wakeUp() override;
|
||||
void interrupt() final;
|
||||
void flush() override;
|
||||
|
||||
|
@ -33,6 +33,14 @@
|
||||
|
||||
#include <emscripten.h>
|
||||
|
||||
#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 <emscripten/threading.h>
|
||||
#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<QWasmEventDispatcher *>(eventDispatcher)->processEvents(QEventLoop::AllEvents);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user