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 committed Oct 15, 2023
1 parent f15923c commit 5724857
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
39 changes: 27 additions & 12 deletions src/library/coverartcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ void CoverArtCache::tryLoadCover(
return;
}

const auto requestedCacheKey = coverInfo.cacheKey();
QString cacheKey = pixmapCacheKey(requestedCacheKey, desiredWidth);
// 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);
const mixxx::cache_key_t requestedCacheKey = coverInfo.cacheKey();
// keep a list of cache keys for which a future is currently running
// to avoid loading the same picture again while we are loading it.
// This fixes also https://github.com/mixxxdj/mixxx/issues/11131 on
// Windows where simultaneous open the same file from two threads fails.
bool requestPending = m_runningRequests.contains(requestedCacheKey);
m_runningRequests.insert(requestedCacheKey, {pRequester, desiredWidth});
if (requestPending) {
return;
}
Expand Down Expand Up @@ -294,11 +295,25 @@ void CoverArtCache::coverLoaded() {
}
}

const QObject* pRequester;
while ((pRequester = m_runningRequests.take(cacheKey)) != nullptr) {
emit coverFound(
pRequester,
res.coverArt,
pixmap);
auto runningRequests = m_runningRequests;
// First remove all requests for this cover that way we can
// re-add cover with different sizes via tryLoadCover() as usual
m_runningRequests::remove(res.coverArt.cacheKey())

Check failure on line 301 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (gcc)

‘m_runningRequests’ is not a class, namespace, or enumeration

Check failure on line 301 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'm_runningRequests': is not a class or namespace name

Check failure on line 301 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'int remove(const char *)': cannot convert argument 1 from 'mixxx::cache_key_t' to 'const char *'

Check failure on line 301 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘m_runningRequests’ is not a class, namespace, or enumeration

Check failure on line 301 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / clazy

'm_runningRequests' is not a class, namespace, or enumeration

Check failure on line 301 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (Qt 6.2, gcc)

‘m_runningRequests’ is not a class, namespace, or enumeration

auto i = runningRequests.find(res.coverArt.cacheKey());

Check failure on line 303 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

syntax error: 'auto' should be preceded by ';'
while (i != runningRequests.end() && i.key() == res.coverArt.cacheKey()) {

Check failure on line 304 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (gcc)

‘i’ was not declared in this scope

Check failure on line 304 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘i’ was not declared in this scope

Check failure on line 304 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'i'

Check failure on line 304 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'i'

Check failure on line 304 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (Qt 6.2, gcc)

‘i’ was not declared in this scope
if (i.value().desiredWidth == res.coverArt.resizedToWidth) {

Check failure on line 305 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'i'
emit coverFound(
i.value().pRequester,

Check failure on line 307 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'i'
res.coverArt,
pixmap);
} else {
tryLoadCover(
i.value().pRequester,

Check failure on line 312 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'i'
nullptr,
res.coverArt,
i.value().desiredWidth);

Check failure on line 315 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'i'
}
++i;

Check failure on line 317 in src/library/coverartcache.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'i'
}
}
6 changes: 5 additions & 1 deletion src/library/coverartcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@ 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;
};
QMultiHash<mixxx::cache_key_t, RequestData> m_runningRequests;
};

0 comments on commit 5724857

Please sign in to comment.