diff --git a/src/corelib/platform/wasm/qstdweb.cpp b/src/corelib/platform/wasm/qstdweb.cpp index 05121ba277..5d17069eec 100644 --- a/src/corelib/platform/wasm/qstdweb.cpp +++ b/src/corelib/platform/wasm/qstdweb.cpp @@ -10,6 +10,8 @@ #include #include #include +#include + #include #include @@ -854,18 +856,33 @@ namespace Promise { } } -bool haveAsyncify() -{ - static bool HaveAsyncify = jsHaveAsyncify(); - return HaveAsyncify; -} - +// Asyncify and thread blocking: Normally, it's not possible to block the main +// thread, except if asyncify is enabled. Secondary threads can always block. +// +// haveAsyncify(): returns true if the main thread can block on QEventLoop::exec(), +// if either asyncify 1 or 2 (JSPI) is available. +// +// haveJspi(): returns true if asyncify 2 (JSPI) is available. +// +// canBlockCallingThread(): returns true if the calling thread can block on +// QEventLoop::exec(), using either asyncify or as a seconarday thread. bool haveJspi() { static bool HaveJspi = jsHaveJspi(); return HaveJspi; } +bool haveAsyncify() +{ + static bool HaveAsyncify = jsHaveAsyncify() || haveJspi(); + return HaveAsyncify; +} + +bool canBlockCallingThread() +{ + return haveAsyncify() || !emscripten_is_main_runtime_thread(); +} + std::shared_ptr readDataTransfer(emscripten::val webDataTransfer, std::function imageReader, std::function)> onDone) diff --git a/src/corelib/platform/wasm/qstdweb_p.h b/src/corelib/platform/wasm/qstdweb_p.h index a7a98ca042..7e94821272 100644 --- a/src/corelib/platform/wasm/qstdweb_p.h +++ b/src/corelib/platform/wasm/qstdweb_p.h @@ -215,6 +215,7 @@ namespace qstdweb { bool haveAsyncify(); bool haveJspi(); + bool canBlockCallingThread(); struct CancellationFlag {