From 7bb61f1a38c74f0c3d2ffbe0c2f960ac047e079d Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 20 Jun 2012 11:04:06 +0200 Subject: [PATCH] * Make sure we have a separate database impl returned for each thread. --- src/libtomahawk/database/Database.cpp | 16 ++++++++++++++++ src/libtomahawk/database/Database.h | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/database/Database.cpp b/src/libtomahawk/database/Database.cpp index eea51aca0..c6ea3938f 100644 --- a/src/libtomahawk/database/Database.cpp +++ b/src/libtomahawk/database/Database.cpp @@ -130,6 +130,22 @@ Database::enqueue( const QSharedPointer& lc ) } +DatabaseImpl* +Database::impl() +{ + QMutexLocker lock( &m_mutex ); + + QThread* thread = QThread::currentThread(); + if ( !m_implHash.contains( thread ) ) + { + DatabaseImpl* impl = m_impl->clone(); + m_implHash.insert( thread, impl ); + } + + return m_implHash.value( thread ); +} + + QString Database::dbid() const { diff --git a/src/libtomahawk/database/Database.h b/src/libtomahawk/database/Database.h index 31c11a14b..914cd593c 100644 --- a/src/libtomahawk/database/Database.h +++ b/src/libtomahawk/database/Database.h @@ -57,7 +57,7 @@ public: void loadIndex(); bool isReady() const { return m_ready; } - DatabaseImpl* impl() const { return m_impl; } + DatabaseImpl* impl(); signals: void indexReady(); // search index @@ -81,6 +81,9 @@ private: QList m_workers; int m_maxConcurrentThreads; + QHash< QThread*, DatabaseImpl* > m_implHash; + QMutex m_mutex; + static Database* s_instance; friend class Tomahawk::Artist;