diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-06-02 10:59:21 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-06-03 18:40:34 +0200 |
commit | 87d32424de2f471a520c1f3ba0c3035fbff7ee06 (patch) | |
tree | d747902db6df974ef010c90e9ce1b0bd7368260b /src/gui/image/qimage_conversions.cpp | |
parent | 6a31a7b024679c4dcbcf8120b06db0a17fa219ce (diff) |
Do not multithread if already in a global threadpool thread
This can lead to a deadlock if we block all the worker threads, waiting
for the worker threads to finish.
Pick-to: 5.15
Fixes: QTBUG-84619
Change-Id: I92b7f96007897d86ece0c34223bab0df4ccbed9a
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/gui/image/qimage_conversions.cpp')
-rw-r--r-- | src/gui/image/qimage_conversions.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp index 357b936db9..134f17a9d1 100644 --- a/src/gui/image/qimage_conversions.cpp +++ b/src/gui/image/qimage_conversions.cpp @@ -237,14 +237,15 @@ void convert_generic(QImageData *dest, const QImageData *src, Qt::ImageConversio int segments = src->nbytes / (1<<16); segments = std::min(segments, src->height); - if (segments <= 1) + QThreadPool *threadPool = QThreadPool::globalInstance(); + if (segments <= 1 || threadPool->contains(QThread::currentThread())) return convertSegment(0, src->height); QSemaphore semaphore; int y = 0; for (int i = 0; i < segments; ++i) { int yn = (src->height - y) / (segments - i); - QThreadPool::globalInstance()->start([&, y, yn]() { + threadPool->start([&, y, yn]() { convertSegment(y, y + yn); semaphore.release(1); }); @@ -291,14 +292,15 @@ void convert_generic_to_rgb64(QImageData *dest, const QImageData *src, Qt::Image int segments = src->nbytes / (1<<16); segments = std::min(segments, src->height); - if (segments <= 1) + QThreadPool *threadPool = QThreadPool::globalInstance(); + if (segments <= 1 || threadPool->contains(QThread::currentThread())) return convertSegment(0, src->height); QSemaphore semaphore; int y = 0; for (int i = 0; i < segments; ++i) { int yn = (src->height - y) / (segments - i); - QThreadPool::globalInstance()->start([&, y, yn]() { + threadPool->start([&, y, yn]() { convertSegment(y, y + yn); semaphore.release(1); }); @@ -397,12 +399,13 @@ bool convert_generic_inplace(QImageData *data, QImage::Format dst_format, Qt::Im #ifdef QT_USE_THREAD_PARALLEL_IMAGE_CONVERSIONS int segments = data->nbytes / (1<<16); segments = std::min(segments, data->height); - if (segments > 1) { + QThreadPool *threadPool = QThreadPool::globalInstance(); + if (segments > 1 && !threadPool->contains(QThread::currentThread())) { QSemaphore semaphore; int y = 0; for (int i = 0; i < segments; ++i) { int yn = (data->height - y) / (segments - i); - QThreadPool::globalInstance()->start([&, y, yn]() { + threadPool->start([&, y, yn]() { convertSegment(y, y + yn); semaphore.release(1); }); |