mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 22:35:27 +00:00
Make thumbnail code threadsafe
The thumbnailing in qt-models/divepicturemodel.cpp was performed concurrently, but the thumbnailCache was not protected from races. Resolve this by guarding the thumbnalCache accesses with mutexes. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
c73828d605
commit
92ad7865d0
1 changed files with 14 additions and 8 deletions
|
@ -8,20 +8,26 @@
|
|||
#include <QtConcurrent>
|
||||
|
||||
extern QHash <QString, QImage> thumbnailCache;
|
||||
static QMutex thumbnailMutex;
|
||||
|
||||
void scaleImages(PictureEntry &entry)
|
||||
{
|
||||
QMutexLocker l(&thumbnailMutex);
|
||||
if (thumbnailCache.contains(entry.filename) && !thumbnailCache.value(entry.filename).isNull()) {
|
||||
entry.image = thumbnailCache.value(entry.filename);
|
||||
} else {
|
||||
int dim = defaultIconMetrics().sz_pic;
|
||||
QImage p = SHashedImage(entry.picture);
|
||||
if(!p.isNull()) {
|
||||
p = p.scaled(dim, dim, Qt::KeepAspectRatio);
|
||||
thumbnailCache.insert(entry.filename, p);
|
||||
}
|
||||
entry.image = p;
|
||||
return;
|
||||
}
|
||||
l.unlock();
|
||||
|
||||
int dim = defaultIconMetrics().sz_pic;
|
||||
QImage p = SHashedImage(entry.picture);
|
||||
if(!p.isNull()) {
|
||||
p = p.scaled(dim, dim, Qt::KeepAspectRatio);
|
||||
QMutexLocker l(&thumbnailMutex);
|
||||
if (!thumbnailCache.contains(entry.filename))
|
||||
thumbnailCache.insert(entry.filename, p);
|
||||
}
|
||||
entry.image = p;
|
||||
}
|
||||
|
||||
DivePictureModel *DivePictureModel::instance()
|
||||
|
|
Loading…
Add table
Reference in a new issue