wasm: remove QEventLoop workarounds

In general, QEventLoop::exec() _can_ be used as-is on
WebAssembly, provided that the event dispatcher supports
the use case.

Use cases that can work include calling exec() on a
secondary thread, or calling exec() on the main thread
if asyncify is used.

Some use cases will still require special casing for
Wasm, such as the non-asyncified QApplication::exec(),
but that can be handles closer to where the workarounds
needed, for example in QApplication.

This removes the partial support for nested event loops
on the main thread, which did not really work. Also,
we no longer call emscripten_force_exit() on QEvetLoop::exit(),
which makes it possible to exit a top-level event loop
without exiting the process.

Task-number: QTBUG-70185
Change-Id: I3a28f41b8547ed3ba1bdf6a835e6662483e34449
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
bb10
Morten Sørvig 2021-05-20 13:01:15 +02:00 committed by Tor Arne Vestbø
parent 2e12c2caf5
commit 713c2a7af6
1 changed files with 0 additions and 24 deletions

View File

@ -48,10 +48,6 @@
#include "qeventloop_p.h"
#include <private/qthread_p.h>
#ifdef Q_OS_WASM
#include <emscripten.h>
#endif
QT_BEGIN_NAMESPACE
/*!
@ -219,15 +215,6 @@ int QEventLoop::exec(ProcessEventsFlags flags)
if (app && app->thread() == thread())
QCoreApplication::removePostedEvents(app, QEvent::Quit);
#ifdef Q_OS_WASM
// Partial support for nested event loops: Make the runtime throw a JavaSrcript
// exception, which returns control to the browser while preserving the C++ stack.
// Event processing then continues as normal. The sleep call below never returns.
// QTBUG-70185
if (threadData->loopLevel > 1)
emscripten_sleep(1);
#endif
while (!d->exit.loadAcquire())
processEvents(flags | WaitForMoreEvents | EventLoopExec);
@ -290,17 +277,6 @@ void QEventLoop::exit(int returnCode)
d->returnCode.storeRelaxed(returnCode);
d->exit.storeRelease(true);
threadData->eventDispatcher.loadRelaxed()->interrupt();
#ifdef Q_OS_WASM
// QEventLoop::exec() never returns in emscripten. We implement approximate behavior here.
// QTBUG-70185
if (threadData->loopLevel == 1) {
emscripten_force_exit(returnCode);
} else {
d->inExec = false;
--threadData->loopLevel;
}
#endif
}
/*!