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>
bb10
Morten Sørvig 2023-09-13 16:06:27 +02:00
parent 4536ff2533
commit 628692a2f2
2 changed files with 24 additions and 6 deletions

View File

@ -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,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<CancellationFlag>
readDataTransfer(emscripten::val webDataTransfer, std::function<QVariant(QByteArray)> imageReader,
std::function<void(std::unique_ptr<QMimeData>)> onDone)

View File

@ -215,6 +215,7 @@ namespace qstdweb {
bool haveAsyncify();
bool haveJspi();
bool canBlockCallingThread();
struct CancellationFlag
{