diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-10-21 14:45:31 +0200 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-12-21 15:05:19 +0000 |
commit | 5a47e29914d5326c39611eedb1e0a7ccd935977b (patch) | |
tree | b0f7bbe18cc2ea67cac88bd68563b64829e0bccd /src/corelib/global/qlogging.cpp | |
parent | d99800dcacc0c3e09f7d98321e12257ef55b98da (diff) |
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>
Diffstat (limited to 'src/corelib/global/qlogging.cpp')
-rw-r--r-- | src/corelib/global/qlogging.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 6e4da27d5e..7c37d5b432 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -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); } |