mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
Fix stupid error, and hence fix this branch up
This commit is contained in:
@@ -57,7 +57,16 @@ Database::Database( const QString& dbname, QObject* parent )
|
|||||||
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() ) );
|
||||||
|
|
||||||
m_workerRW->start();
|
Q_ASSERT( m_workerRW );
|
||||||
|
m_workerRW.data()->start();
|
||||||
|
|
||||||
|
while ( m_workerThreads.count() < m_maxConcurrentThreads )
|
||||||
|
{
|
||||||
|
QWeakPointer< DatabaseWorkerThread > workerThread( new DatabaseWorkerThread( this, false ) );
|
||||||
|
Q_ASSERT( workerThread );
|
||||||
|
workerThread.data()->start();
|
||||||
|
m_workerThreads << workerThread;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,20 +74,26 @@ Database::~Database()
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_workerRW->quit();
|
if ( m_workerRW )
|
||||||
foreach ( DatabaseWorkerThread *thread, m_workerThreads )
|
m_workerRW.data()->quit();
|
||||||
|
foreach ( QWeakPointer< DatabaseWorkerThread > workerThread, m_workerThreads )
|
||||||
{
|
{
|
||||||
if ( thread->worker() )
|
if ( workerThread && workerThread.data()->worker() )
|
||||||
thread->quit();
|
workerThread.data()->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_workerRW->wait( 60000 );
|
if ( m_workerRW )
|
||||||
delete m_workerRW;
|
|
||||||
m_workerRW = 0;
|
|
||||||
foreach ( DatabaseWorkerThread *thread, m_workerThreads )
|
|
||||||
{
|
{
|
||||||
thread->wait( 60000 );
|
m_workerRW.data()->wait( 60000 );
|
||||||
delete thread;
|
delete m_workerRW.data();
|
||||||
|
}
|
||||||
|
foreach ( QWeakPointer< DatabaseWorkerThread > workerThread, m_workerThreads )
|
||||||
|
{
|
||||||
|
if ( workerThread )
|
||||||
|
{
|
||||||
|
workerThread.data()->wait( 60000 );
|
||||||
|
delete workerThread.data();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_workerThreads.clear();
|
m_workerThreads.clear();
|
||||||
|
|
||||||
@@ -99,8 +114,8 @@ Database::enqueue( const QList< QSharedPointer<DatabaseCommand> >& lc )
|
|||||||
{
|
{
|
||||||
Q_ASSERT( m_ready );
|
Q_ASSERT( m_ready );
|
||||||
qDebug() << "Enqueueing" << lc.count() << "commands to rw thread";
|
qDebug() << "Enqueueing" << lc.count() << "commands to rw thread";
|
||||||
if ( m_workerRW->worker() )
|
if ( m_workerRW && m_workerRW.data()->worker() )
|
||||||
m_workerRW->worker().data()->enqueue( lc );
|
m_workerRW.data()->worker().data()->enqueue( lc );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,44 +126,32 @@ Database::enqueue( const QSharedPointer<DatabaseCommand>& lc )
|
|||||||
if ( lc->doesMutates() )
|
if ( lc->doesMutates() )
|
||||||
{
|
{
|
||||||
qDebug() << "Enqueueing command to rw thread:" << lc->commandname();
|
qDebug() << "Enqueueing command to rw thread:" << lc->commandname();
|
||||||
if ( m_workerRW->worker() )
|
if ( m_workerRW && m_workerRW.data()->worker() )
|
||||||
m_workerRW->worker().data()->enqueue( lc );
|
m_workerRW.data()->worker().data()->enqueue( lc );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// find existing amount of worker threads for commandname
|
|
||||||
// create new thread if < WORKER_THREADS
|
|
||||||
if ( m_workerThreads.count() < m_maxConcurrentThreads )
|
|
||||||
{
|
|
||||||
DatabaseWorkerThread* workerThread = new DatabaseWorkerThread( this, false );
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "P1" << ( workerThread->worker() ? "true" : "false" );
|
|
||||||
workerThread->start();
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "P2" << ( workerThread->worker() ? "true" : "false" );
|
|
||||||
|
|
||||||
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< DatabaseWorkerThread > workerThread;
|
||||||
QWeakPointer< DatabaseWorker > happyWorker;
|
QWeakPointer< DatabaseWorker > happyWorker;
|
||||||
for ( int i = 0; i < m_workerThreads.count(); i++ )
|
for ( int i = 0; i < m_workerThreads.count(); i++ )
|
||||||
{
|
{
|
||||||
DatabaseWorkerThread* workerThread = m_workerThreads.at( i );
|
workerThread = m_workerThreads.at( i );
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << i << ( workerThread->worker() ? "true" : "false" );
|
if ( workerThread && workerThread.data()->worker() && !workerThread.data()->worker().data()->busy() )
|
||||||
if ( workerThread->worker() && !workerThread->worker().data()->busy() )
|
|
||||||
{
|
{
|
||||||
happyWorker = workerThread->worker();
|
happyWorker = workerThread.data()->worker();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
busyThreads++;
|
busyThreads++;
|
||||||
|
|
||||||
if ( !happyWorker || ( workerThread->worker() && workerThread->worker().data()->outstandingJobs() < happyWorker.data()->outstandingJobs() ) )
|
if ( ( !happyWorker && workerThread && workerThread.data()->worker() ) ||
|
||||||
happyWorker = workerThread->worker();
|
( workerThread && workerThread.data()->worker() && workerThread.data()->worker().data()->outstandingJobs() < happyWorker.data()->outstandingJobs() ) )
|
||||||
|
happyWorker = workerThread.data()->worker();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 );
|
Q_ASSERT( happyWorker );
|
||||||
happyWorker.data()->enqueue( lc );
|
happyWorker.data()->enqueue( lc );
|
||||||
}
|
}
|
||||||
|
@@ -76,8 +76,8 @@ private:
|
|||||||
bool m_ready;
|
bool m_ready;
|
||||||
|
|
||||||
DatabaseImpl* m_impl;
|
DatabaseImpl* m_impl;
|
||||||
DatabaseWorkerThread* m_workerRW;
|
QWeakPointer< DatabaseWorkerThread > m_workerRW;
|
||||||
QList< DatabaseWorkerThread* > m_workerThreads;
|
QList< QWeakPointer< DatabaseWorkerThread > > m_workerThreads;
|
||||||
int m_maxConcurrentThreads;
|
int m_maxConcurrentThreads;
|
||||||
|
|
||||||
QHash< QThread*, DatabaseImpl* > m_implHash;
|
QHash< QThread*, DatabaseImpl* > m_implHash;
|
||||||
|
@@ -48,7 +48,6 @@ DatabaseWorkerThread::run()
|
|||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "DatabaseWorkerThread starting...";
|
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 << "DatabaseWorkerThread finishing...";
|
tDebug() << Q_FUNC_INFO << "DatabaseWorkerThread finishing...";
|
||||||
if ( m_worker )
|
if ( m_worker )
|
||||||
@@ -64,7 +63,6 @@ DatabaseWorkerThread::~DatabaseWorkerThread()
|
|||||||
QWeakPointer< DatabaseWorker >
|
QWeakPointer< DatabaseWorker >
|
||||||
DatabaseWorkerThread::worker() const
|
DatabaseWorkerThread::worker() const
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "P4" << ( m_worker ? "true" : "false" );
|
|
||||||
return m_worker;
|
return m_worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user