mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +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>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
extern QHash <QString, QImage> thumbnailCache;
|
extern QHash <QString, QImage> thumbnailCache;
|
||||||
|
static QMutex thumbnailMutex;
|
||||||
|
|
||||||
void scaleImages(PictureEntry &entry)
|
void scaleImages(PictureEntry &entry)
|
||||||
{
|
{
|
||||||
|
QMutexLocker l(&thumbnailMutex);
|
||||||
if (thumbnailCache.contains(entry.filename) && !thumbnailCache.value(entry.filename).isNull()) {
|
if (thumbnailCache.contains(entry.filename) && !thumbnailCache.value(entry.filename).isNull()) {
|
||||||
entry.image = thumbnailCache.value(entry.filename);
|
entry.image = thumbnailCache.value(entry.filename);
|
||||||
} else {
|
return;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
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()
|
DivePictureModel *DivePictureModel::instance()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue