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>
bb10
Morten Johan Sørvig 2021-10-08 11:03:44 +02:00
parent 966f7cb5dd
commit 0a8a4698d6
1 changed files with 10 additions and 2 deletions

View File

@ -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