summaryrefslogtreecommitdiffstats
path: root/src/corelib/platform
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2023-09-13 16:06:27 +0200
committerMorten Sørvig <morten.sorvig@qt.io>2023-10-02 09:41:50 +0200
commit628692a2f2950b7c25dfa45637d7d063792188cb (patch)
treeea9563aa790b0fb60324ddbfa2bd6474699edc1e /src/corelib/platform
parent4536ff2533bae71cd4f384e5c64d89d12ab4a672 (diff)
wasm: make haveAsyncify() return true for any asyncify
User code usually don't need to differentiate between asyncify 1 or 2 (JSPI), since the differences are abstracted over by the wasm event dispatcher. haveJspi() returns true for JSPI only as before, and can be used to differentiate between the two. Add canBlockCallingThread(), which returns true also for secondary threads (which don't need asyncify to block). Change-Id: Ia37513f2d4c56ef6351c950b5fc31ad15fa389d9 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/corelib/platform')
-rw-r--r--src/corelib/platform/wasm/qstdweb.cpp25
-rw-r--r--src/corelib/platform/wasm/qstdweb_p.h1
2 files changed, 22 insertions, 4 deletions
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 <emscripten/bind.h>
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
+#include <emscripten/threading.h>
+
#include <cstdint>
#include <iostream>
@@ -854,16 +856,31 @@ namespace Promise {
}
}
+// 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();
+ static bool HaveAsyncify = jsHaveAsyncify() || haveJspi();
return HaveAsyncify;
}
-bool haveJspi()
+bool canBlockCallingThread()
{
- static bool HaveJspi = jsHaveJspi();
- return HaveJspi;
+ return haveAsyncify() || !emscripten_is_main_runtime_thread();
}
std::shared_ptr<CancellationFlag>
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
{