mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
* Be cleverer with database threads, too.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
#define WORKER_THREADS 5
|
#define DEFAULT_WORKER_THREADS 4
|
||||||
|
#define MAX_WORKER_THREADS 16
|
||||||
|
|
||||||
Database* Database::s_instance = 0;
|
Database* Database::s_instance = 0;
|
||||||
|
|
||||||
@@ -38,6 +39,9 @@ Database::Database( const QString& dbname, QObject* parent )
|
|||||||
{
|
{
|
||||||
s_instance = this;
|
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( indexReady() ) );
|
||||||
connect( m_impl, SIGNAL( indexReady() ), SIGNAL( ready() ) );
|
connect( m_impl, SIGNAL( indexReady() ), SIGNAL( ready() ) );
|
||||||
connect( m_impl, SIGNAL( indexReady() ), SLOT( setIsReadyTrue() ) );
|
connect( m_impl, SIGNAL( indexReady() ), SLOT( setIsReadyTrue() ) );
|
||||||
@@ -76,7 +80,7 @@ Database::enqueue( QSharedPointer<DatabaseCommand> lc )
|
|||||||
{
|
{
|
||||||
// find existing amount of worker threads for commandname
|
// find existing amount of worker threads for commandname
|
||||||
// create new thread if < WORKER_THREADS
|
// 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 );
|
DatabaseWorker* worker = new DatabaseWorker( m_impl, this, false );
|
||||||
worker->start();
|
worker->start();
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
bool indexReady() const { return m_indexReady; }
|
bool indexReady() const { return m_indexReady; }
|
||||||
|
|
||||||
void loadIndex();
|
void loadIndex();
|
||||||
|
|
||||||
bool isReady() const { return m_ready; }
|
bool isReady() const { return m_ready; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -67,13 +67,14 @@ public slots:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void setIsReadyTrue() { m_ready = true; }
|
void setIsReadyTrue() { m_ready = true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
DatabaseImpl* m_impl;
|
DatabaseImpl* m_impl;
|
||||||
DatabaseWorker* m_workerRW;
|
DatabaseWorker* m_workerRW;
|
||||||
QHash< QString, DatabaseWorker* > m_workers;
|
QHash< QString, DatabaseWorker* > m_workers;
|
||||||
bool m_indexReady;
|
bool m_indexReady;
|
||||||
|
int m_maxConcurrentThreads;
|
||||||
|
|
||||||
static Database* s_instance;
|
static Database* s_instance;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user