wasm: prevent thread cross-talk when logging

Emscriptens implementation of fprintf does not provide
mutal exclusion when called from multiple threads, for
the emsdk versions Qt 5.15, Qt 6.2, and current dev
is using.

Pick-to: 5.15 6.2
Change-Id: Ied92730b735b11e4e5e85442de48fc25cbad0611
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Morten Johan Sørvig 2021-10-21 14:45:31 +02:00
parent d99800dcac
commit 5a47e29914

View File

@ -1748,6 +1748,13 @@ static void stderr_message_handler(QtMsgType type, const QMessageLogContext &con
if (formattedMessage.isNull())
return;
#ifdef Q_OS_WASM
// Prevent thread cross-talk, which causes Emscripten to log
// non-valid UTF-8. FIXME: remove once we upgrade to emsdk > 2.0.30
static QBasicMutex m;
auto locker = qt_unique_lock(m);
#endif
fprintf(stderr, "%s\n", formattedMessage.toLocal8Bit().constData());
fflush(stderr);
}