summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2020-03-31 00:53:41 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2020-04-05 22:20:55 +0200
commitf9137c8c6ec9174a9b92234bc8b49ee2445798b9 (patch)
tree6df1a54d433bc633edfbd3638c3efdb36cb27cd8 /src/gui
parent1c23d34ad4bdd67dec6d501d91087823dc9ea358 (diff)
Wasm: don’t deadlock on parallel image conversions
A special restriction of threads on WebAssembly is that you should not block the main thread, also not to wait for worker threads. For example, blocking the main thread may prevent the browser from starting a new web worker to service the pthread the main thread is waiting for. We may be able create an abstraction to support use cases like this (most likely using emscripten asyncify), but for disable use of threads to avoid deadlocking. Change-Id: I35edd5e1bb465e2549fa7cc4288b47dcd2e4244b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qimage_conversions.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp
index 853bbe4f8e..34d2b8d8c7 100644
--- a/src/gui/image/qimage_conversions.cpp
+++ b/src/gui/image/qimage_conversions.cpp
@@ -48,6 +48,11 @@
#if QT_CONFIG(thread)
#include <qsemaphore.h>
#include <qthreadpool.h>
+#ifdef Q_OS_WASM
+// WebAssembly has threads; however we can't block the main thread.
+#else
+#define QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS
+#endif
#endif
QT_BEGIN_NAMESPACE
@@ -227,7 +232,7 @@ void convert_generic(QImageData *dest, const QImageData *src, Qt::ImageConversio
}
};
-#if QT_CONFIG(thread)
+#ifdef QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS
int segments = src->nbytes / (1<<16);
segments = std::min(segments, src->height);
@@ -281,7 +286,7 @@ void convert_generic_to_rgb64(QImageData *dest, const QImageData *src, Qt::Image
destData += dest->bytes_per_line;
}
};
-#if QT_CONFIG(thread)
+#ifdef QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS
int segments = src->nbytes / (1<<16);
segments = std::min(segments, src->height);
@@ -388,7 +393,7 @@ bool convert_generic_inplace(QImageData *data, QImage::Format dst_format, Qt::Im
destData += params.bytesPerLine;
}
};
-#if QT_CONFIG(thread)
+#ifdef QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS
int segments = data->nbytes / (1<<16);
segments = std::min(segments, data->height);
if (segments > 1) {