summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2021-10-08 11:03:44 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2021-11-11 15:24:36 +0000
commit0a8a4698d65d1a579edfa29d6a62644eedd64a70 (patch)
treec4afdb1632bfe0a536f55739af18e3343d95262f /src/corelib/kernel
parent966f7cb5dddfe87f23701c12eeb071bd798a9e40 (diff)
wasm: fix native timer update for the no-timer case
QTimerInfoList::timerWait() does not update the timespec out argument if there are no active timers, which caused the current code to calculate an arbitrary toWaitDuration. Instead use the timerWait() return value, and clear any native timers if there are no active Qt timers. Pick-to: 6.2 Change-Id: I7d5ec4c2930000bece6f6ea6c63e76f4df543b04 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qeventdispatcher_wasm.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp
index 15ada58aad..b499cf91fe 100644
--- a/src/corelib/kernel/qeventdispatcher_wasm.cpp
+++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp
@@ -480,14 +480,22 @@ void QEventDispatcherWasm::updateNativeTimer()
return ts.tv_sec * 1000 + ts.tv_nsec / (1000 * 1000);
};
timespec toWait;
- m_timerInfo->timerWait(toWait);
+ bool hasTimer = m_timerInfo->timerWait(toWait);
uint64_t currentTime = timespecToNanosec(m_timerInfo->currentTime);
uint64_t toWaitDuration = timespecToNanosec(toWait);
uint64_t newTargetTime = currentTime + toWaitDuration;
- auto maintainNativeTimer = [this, toWaitDuration, newTargetTime]() {
+ auto maintainNativeTimer = [this, hasTimer, toWaitDuration, newTargetTime]() {
Q_ASSERT(emscripten_is_main_runtime_thread());
+ if (!hasTimer) {
+ if (m_timerId > 0) {
+ emscripten_clear_timeout(m_timerId);
+ m_timerId = 0;
+ }
+ return;
+ }
+
if (m_timerTargetTime != 0 && newTargetTime >= m_timerTargetTime)
return; // existing timer is good