From 46fc9cb20a73c85827c77d578b2605fd88e71feb Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 15 Jun 2011 04:15:27 +0200 Subject: [PATCH] * Be cleverer with database threads, too. --- src/libtomahawk/database/database.cpp | 10 +++++++--- src/libtomahawk/database/database.h | 7 ++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libtomahawk/database/database.cpp b/src/libtomahawk/database/database.cpp index 4436f6cfa..bd6b81e49 100644 --- a/src/libtomahawk/database/database.cpp +++ b/src/libtomahawk/database/database.cpp @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -18,7 +18,8 @@ #include "database.h" -#define WORKER_THREADS 5 +#define DEFAULT_WORKER_THREADS 4 +#define MAX_WORKER_THREADS 16 Database* Database::s_instance = 0; @@ -38,6 +39,9 @@ Database::Database( const QString& dbname, QObject* parent ) { s_instance = this; + m_maxConcurrentThreads = qBound( DEFAULT_WORKER_THREADS, QThread::idealThreadCount() * 2, MAX_WORKER_THREADS ); + qDebug() << Q_FUNC_INFO << "Using" << m_maxConcurrentThreads << "threads"; + connect( m_impl, SIGNAL( indexReady() ), SIGNAL( indexReady() ) ); connect( m_impl, SIGNAL( indexReady() ), SIGNAL( ready() ) ); connect( m_impl, SIGNAL( indexReady() ), SLOT( setIsReadyTrue() ) ); @@ -76,7 +80,7 @@ Database::enqueue( QSharedPointer lc ) { // find existing amount of worker threads for commandname // create new thread if < WORKER_THREADS - if ( m_workers.count( lc->commandname() ) < WORKER_THREADS ) + if ( m_workers.count( lc->commandname() ) < m_maxConcurrentThreads ) { DatabaseWorker* worker = new DatabaseWorker( m_impl, this, false ); worker->start(); diff --git a/src/libtomahawk/database/database.h b/src/libtomahawk/database/database.h index df02ce2a0..678cca01b 100644 --- a/src/libtomahawk/database/database.h +++ b/src/libtomahawk/database/database.h @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -52,7 +52,7 @@ public: bool indexReady() const { return m_indexReady; } void loadIndex(); - + bool isReady() const { return m_ready; } signals: @@ -67,13 +67,14 @@ public slots: private slots: void setIsReadyTrue() { m_ready = true; } - + private: bool m_ready; DatabaseImpl* m_impl; DatabaseWorker* m_workerRW; QHash< QString, DatabaseWorker* > m_workers; bool m_indexReady; + int m_maxConcurrentThreads; static Database* s_instance; };