summaryrefslogtreecommitdiffstats
path: root/src/track
diff options
context:
space:
mode:
authorUwe Klotz <uklotz@mixxx.org>2020-06-06 09:30:34 +0200
committerUwe Klotz <uklotz@mixxx.org>2020-06-06 10:52:43 +0200
commit1def3a31a626245253b4a98c72e27cd58e05a31d (patch)
treec54a37da3197b9a5d808c9f76a7ead43d8c69af2 /src/track
parent1f3fc6e97bf7a46c531aaa1ffa83010955ab6404 (diff)
Detect thread affinity violations
Diffstat (limited to 'src/track')
-rw-r--r--src/track/globaltrackcache.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/track/globaltrackcache.cpp b/src/track/globaltrackcache.cpp
index 257c58af5b..8cff786eb0 100644
--- a/src/track/globaltrackcache.cpp
+++ b/src/track/globaltrackcache.cpp
@@ -1,11 +1,10 @@
#include "track/globaltrackcache.h"
-#include <QApplication>
-#include <QThread>
+#include <QCoreApplication>
#include "util/assert.h"
#include "util/logger.h"
-
+#include "util/thread_affinity.h"
namespace {
@@ -209,7 +208,8 @@ void GlobalTrackCache::createInstance(
//static
void GlobalTrackCache::destroyInstance() {
- DEBUG_ASSERT(s_pInstance);
+ DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(s_pInstance);
+
kLogger.info() << "Destroying instance";
// Processing all pending events is required to evict all
// remaining references from the cache.
@@ -220,7 +220,6 @@ void GlobalTrackCache::destroyInstance() {
// Reset the static/global pointer before entering the destructor
s_pInstance = nullptr;
// Delete the singular instance
- DEBUG_ASSERT(QThread::currentThread() == pInstance->thread());
pInstance->deleteLater();
}
@@ -264,7 +263,7 @@ void GlobalTrackCache::evictAndSaveCachedTrack(GlobalTrackCacheEntryPointer cach
"evictAndSave"
#else
[cacheEntryPtr = std::move(cacheEntryPtr)] {
- s_pInstance->evictAndSave(cacheEntryPtr);
+ s_pInstance->slotEvictAndSave(cacheEntryPtr);
}
#endif
// Qt will choose either a direct or a queued connection
@@ -371,7 +370,7 @@ void GlobalTrackCache::saveEvictedTrack(Track* pEvictedTrack) const {
}
void GlobalTrackCache::deactivate() {
- DEBUG_ASSERT(QThread::currentThread() == QCoreApplication::instance()->thread());
+ DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
if (isEmpty()) {
return;
@@ -625,7 +624,7 @@ void GlobalTrackCache::resolve(
// function might be called from any thread, even from worker
// threads without an event loop. We need to move the newly
// created object to the main thread.
- savingPtr->moveToThread(QApplication::instance()->thread());
+ savingPtr->moveToThread(QCoreApplication::instance()->thread());
pCacheResolver->initLookupResult(
GlobalTrackCacheLookupResult::MISS,
@@ -672,6 +671,7 @@ void GlobalTrackCache::purgeTrackId(TrackId trackId) {
void GlobalTrackCache::evictAndSave(
GlobalTrackCacheEntryPointer cacheEntryPtr) {
+ DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
DEBUG_ASSERT(cacheEntryPtr);
// We need to be sure this is always called from the main thread
@@ -679,7 +679,6 @@ void GlobalTrackCache::evictAndSave(
// the lock until all changes are persistently stored in file and DB
// to not hand out the track again with old metadata.
DEBUG_ASSERT(QApplication::instance()->thread() == QThread::currentThread());
-
GlobalTrackCacheLocker cacheLocker;
if (!cacheEntryPtr->expired()) {