mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 01:54:07 +02:00
More work
This commit is contained in:
@@ -66,7 +66,7 @@ Database::~Database()
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_workerRW->quit();
|
m_workerRW->quit();
|
||||||
foreach ( DatabaseWorkerThread *thread, m_workers )
|
foreach ( DatabaseWorkerThread *thread, m_workerThreads )
|
||||||
{
|
{
|
||||||
if ( thread->worker() )
|
if ( thread->worker() )
|
||||||
thread->quit();
|
thread->quit();
|
||||||
@@ -75,12 +75,12 @@ Database::~Database()
|
|||||||
m_workerRW->wait( 60000 );
|
m_workerRW->wait( 60000 );
|
||||||
delete m_workerRW;
|
delete m_workerRW;
|
||||||
m_workerRW = 0;
|
m_workerRW = 0;
|
||||||
foreach ( DatabaseWorkerThread *thread, m_workers )
|
foreach ( DatabaseWorkerThread *thread, m_workerThreads )
|
||||||
{
|
{
|
||||||
thread->wait( 60000 );
|
thread->wait( 60000 );
|
||||||
delete thread;
|
delete thread;
|
||||||
}
|
}
|
||||||
m_workers.clear();
|
m_workerThreads.clear();
|
||||||
|
|
||||||
qDeleteAll( m_implHash.values() );
|
qDeleteAll( m_implHash.values() );
|
||||||
delete m_impl;
|
delete m_impl;
|
||||||
@@ -118,21 +118,24 @@ Database::enqueue( const 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() < m_maxConcurrentThreads )
|
if ( m_workerThreads.count() < m_maxConcurrentThreads )
|
||||||
{
|
{
|
||||||
DatabaseWorkerThread* worker = new DatabaseWorkerThread( this, false );
|
DatabaseWorkerThread* workerThread = new DatabaseWorkerThread( this, false );
|
||||||
worker->start();
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "P1" << ( workerThread->worker() ? "true" : "false" );
|
||||||
|
workerThread->start();
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "P2" << ( workerThread->worker() ? "true" : "false" );
|
||||||
|
|
||||||
m_workers << worker;
|
m_workerThreads << workerThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find thread for commandname with lowest amount of outstanding jobs and enqueue job
|
// find thread for commandname with lowest amount of outstanding jobs and enqueue job
|
||||||
int busyThreads = 0;
|
int busyThreads = 0;
|
||||||
QWeakPointer< DatabaseWorker > happyWorker;
|
QWeakPointer< DatabaseWorker > happyWorker;
|
||||||
for ( int i = 0; i < m_workers.count(); i++ )
|
for ( int i = 0; i < m_workerThreads.count(); i++ )
|
||||||
{
|
{
|
||||||
DatabaseWorkerThread* workerThread = m_workers.at( i );
|
DatabaseWorkerThread* workerThread = m_workerThreads.at( i );
|
||||||
|
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << i << ( workerThread->worker() ? "true" : "false" );
|
||||||
if ( workerThread->worker() && !workerThread->worker().data()->busy() )
|
if ( workerThread->worker() && !workerThread->worker().data()->busy() )
|
||||||
{
|
{
|
||||||
happyWorker = workerThread->worker();
|
happyWorker = workerThread->worker();
|
||||||
@@ -145,6 +148,8 @@ Database::enqueue( const QSharedPointer<DatabaseCommand>& lc )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// qDebug() << "Enqueueing command to thread:" << happyThread << busyThreads << lc->commandname();
|
// qDebug() << "Enqueueing command to thread:" << happyThread << busyThreads << lc->commandname();
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_workerThreads.count() << m_maxConcurrentThreads;
|
||||||
|
Q_ASSERT( happyWorker );
|
||||||
happyWorker.data()->enqueue( lc );
|
happyWorker.data()->enqueue( lc );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -77,7 +77,7 @@ private:
|
|||||||
|
|
||||||
DatabaseImpl* m_impl;
|
DatabaseImpl* m_impl;
|
||||||
DatabaseWorkerThread* m_workerRW;
|
DatabaseWorkerThread* m_workerRW;
|
||||||
QList< DatabaseWorkerThread* > m_workers;
|
QList< DatabaseWorkerThread* > m_workerThreads;
|
||||||
int m_maxConcurrentThreads;
|
int m_maxConcurrentThreads;
|
||||||
|
|
||||||
QHash< QThread*, DatabaseImpl* > m_implHash;
|
QHash< QThread*, DatabaseImpl* > m_implHash;
|
||||||
|
@@ -40,17 +40,17 @@ DatabaseWorkerThread::DatabaseWorkerThread( Database* db, bool mutates )
|
|||||||
, m_db( db )
|
, m_db( db )
|
||||||
, m_mutates( mutates )
|
, m_mutates( mutates )
|
||||||
{
|
{
|
||||||
Q_UNUSED( db );
|
|
||||||
Q_UNUSED( mutates );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseWorkerThread::run()
|
DatabaseWorkerThread::run()
|
||||||
{
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO << "DatabaseWorkerThread starting...";
|
||||||
m_worker = QWeakPointer< DatabaseWorker >( new DatabaseWorker( m_db, m_mutates ) );
|
m_worker = QWeakPointer< DatabaseWorker >( new DatabaseWorker( m_db, m_mutates ) );
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "P5" << ( m_worker ? "true" : "false" );
|
||||||
exec();
|
exec();
|
||||||
tDebug() << Q_FUNC_INFO << "DatabaseWorker finishing...";
|
tDebug() << Q_FUNC_INFO << "DatabaseWorkerThread finishing...";
|
||||||
if ( m_worker )
|
if ( m_worker )
|
||||||
delete m_worker.data();
|
delete m_worker.data();
|
||||||
}
|
}
|
||||||
@@ -61,13 +61,19 @@ DatabaseWorkerThread::~DatabaseWorkerThread()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QWeakPointer< DatabaseWorker >
|
||||||
|
DatabaseWorkerThread::worker() const
|
||||||
|
{
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "P4" << ( m_worker ? "true" : "false" );
|
||||||
|
return m_worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DatabaseWorker::DatabaseWorker( Database* db, bool mutates )
|
DatabaseWorker::DatabaseWorker( Database* db, bool mutates )
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_db( db )
|
, m_db( db )
|
||||||
, m_outstanding( 0 )
|
, m_outstanding( 0 )
|
||||||
{
|
{
|
||||||
Q_UNUSED( db );
|
|
||||||
Q_UNUSED( mutates );
|
Q_UNUSED( mutates );
|
||||||
tDebug() << Q_FUNC_INFO << "New db connection with name:" << Database::instance()->impl()->database().connectionName() << "on thread" << this->thread();
|
tDebug() << Q_FUNC_INFO << "New db connection with name:" << Database::instance()->impl()->database().connectionName() << "on thread" << this->thread();
|
||||||
}
|
}
|
||||||
@@ -84,9 +90,6 @@ DatabaseWorker::~DatabaseWorker()
|
|||||||
tDebug() << "Outstanding db command to finish:" << cmd->guid() << cmd->commandname();
|
tDebug() << "Outstanding db command to finish:" << cmd->guid() << cmd->commandname();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread()->quit();
|
|
||||||
wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -71,7 +71,7 @@ public:
|
|||||||
DatabaseWorkerThread( Database* db, bool mutates );
|
DatabaseWorkerThread( Database* db, bool mutates );
|
||||||
~DatabaseWorkerThread();
|
~DatabaseWorkerThread();
|
||||||
|
|
||||||
QWeakPointer< DatabaseWorker > worker() { return m_worker; }
|
QWeakPointer< DatabaseWorker > worker() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
|
Reference in New Issue
Block a user