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>
This commit is contained in:
Morten Johan Sørvig 2020-03-31 00:53:41 +02:00
parent 1c23d34ad4
commit f9137c8c6e

View File

@ -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) {