Skip to content

Commit

Permalink
Avoid simultaneous access of the same file for two diffrent width
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer authored Oct 12, 2023
1 parent 165de84 commit e66a7b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/library/coverartcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ void CoverArtCache::tryLoadCover(
return;
}

const auto requestedCacheKey = coverInfo.cacheKey();
QString cacheKey = pixmapCacheKey(requestedCacheKey, desiredWidth);
const mixxx::cache_key_t requestedCacheKey = coverInfo.cacheKey();
// keep a list of cacheKeys for which a future is currently running
// to avoid loading the same picture again while we are loading it
bool requestPending = m_runningRequests.contains(cacheKey);
m_runningRequests.insert(cacheKey, pRequester);
bool requestPending = m_runningRequests.contains(requestedCacheKey);
m_runningRequests.insert(requestedCacheKey, {pRequester, desiredWidth});
if (requestPending) {
return;
}
Expand Down Expand Up @@ -294,11 +293,21 @@ void CoverArtCache::coverLoaded() {
}
}

const QObject* pRequester;
while ((pRequester = m_runningRequests.take(cacheKey)) != nullptr) {
emit coverFound(
pRequester,
QMultiHash<QString, int>::iterator i = m_runningRequests.find(res.coverArt.cacheKey());
while (i != hash.end() && i.key() == res.coverArt.cacheKey()) {
if (i.value().desiredWidth == res.coverArt.resizedToWidth) {
emit coverFound(
i.value().pRequester,
res.coverArt,
pixmap);
} else {
tryLoadCover(
i.value().pRequester,
nullptr,
res.coverArt,
pixmap);
res.coverArt.resizedToWidth);
}
hash.erase(i);
++i;
}
}
9 changes: 8 additions & 1 deletion src/library/coverartcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,12 @@ class CoverArtCache : public QObject, public Singleton<CoverArtCache> {
const CoverInfo& info,
int desiredWidth);

QMultiHash<QString, const QObject*> m_runningRequests;
struct RequestData {
const QObject* pRequester;
int desiredWidth;
}

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (gcc)

expected ‘;’ after struct definition

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (Qt 6.2, gcc)

expected ‘;’ after struct definition

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

expected ';' after struct

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

expected ';' after struct

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

expected ';' after struct

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

expected ';' after struct

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

expected ';' after struct

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

expected ‘;’ after struct definition

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

expected ‘;’ after struct definition

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

expected ‘;’ after struct definition

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

expected ‘;’ after struct definition

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

expected ‘;’ after struct definition

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

expected ';' after struct [clang-diagnostic-error]

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

expected ';' after struct [clang-diagnostic-error]

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

expected ';' after struct [clang-diagnostic-error]

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

expected ';' after struct [clang-diagnostic-error]

Check failure on line 98 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

expected ';' after struct [clang-diagnostic-error]
bool operator==(const RequestData& l, const RequestData& r) {

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'CoverArtCache::RequestData' followed by 'bool' is illegal (did you forget a ';'?)

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

binary 'operator ==' has too many parameters

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'CoverArtCache::operator ==': error in function declaration; skipping function body

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (gcc)

‘bool CoverArtCache::operator==(const CoverArtCache::RequestData&, const CoverArtCache::RequestData&)’ must have exactly one argument

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (Qt 6.2, gcc)

‘bool CoverArtCache::operator==(const CoverArtCache::RequestData&, const CoverArtCache::RequestData&)’ must have exactly one argument

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

overloaded 'operator==' must be a binary operator (has 3 parameters)

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

overloaded 'operator==' must be a binary operator (has 3 parameters)

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

overloaded 'operator==' must be a binary operator (has 3 parameters)

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

overloaded 'operator==' must be a binary operator (has 3 parameters)

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clazy

overloaded 'operator==' must be a binary operator (has 3 parameters)

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

‘bool CoverArtCache::operator==(const CoverArtCache::RequestData&, const CoverArtCache::RequestData&)’ must have exactly one argument

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

‘bool CoverArtCache::operator==(const CoverArtCache::RequestData&, const CoverArtCache::RequestData&)’ must have exactly one argument

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

‘bool CoverArtCache::operator==(const CoverArtCache::RequestData&, const CoverArtCache::RequestData&)’ must have exactly one argument

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

‘bool CoverArtCache::operator==(const CoverArtCache::RequestData&, const CoverArtCache::RequestData&)’ must have exactly one argument

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / coverage

‘bool CoverArtCache::operator==(const CoverArtCache::RequestData&, const CoverArtCache::RequestData&)’ must have exactly one argument

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

overloaded 'operator==' must be a binary operator (has 3 parameters) [clang-diagnostic-error]

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

overloaded 'operator==' must be a binary operator (has 3 parameters) [clang-diagnostic-error]

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

overloaded 'operator==' must be a binary operator (has 3 parameters) [clang-diagnostic-error]

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

overloaded 'operator==' must be a binary operator (has 3 parameters) [clang-diagnostic-error]

Check failure on line 99 in src/library/coverartcache.h

View workflow job for this annotation

GitHub Actions / clang-tidy

overloaded 'operator==' must be a binary operator (has 3 parameters) [clang-diagnostic-error]
return l.pRequester == r.pRequester && l.desiredWidth == r.desiredWidth;
}
QMultiHash<mixxx::cache_key_t, RequestData> m_runningRequests;
};

0 comments on commit e66a7b3

Please sign in to comment.