1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Readability++, Comments++

This commit is contained in:
Uwe L. Korn
2014-10-12 16:27:49 +01:00
parent b62a930962
commit cb373ca65c

View File

@@ -242,17 +242,38 @@ Database::enqueue( const Tomahawk::dbcmd_ptr& lc )
{
workerThread = m_workerThreads.at( i );
if ( workerThread && workerThread->worker() && !workerThread->worker()->busy() )
if ( !workerThread || !workerThread->worker() )
{
// We have no valid worker for the current thread so skip it.
continue;
}
if ( !workerThread->worker()->busy() )
{
// Case 1: We have a workerThread with no outstanding jobs.
// As this is the optimal situation we do not need to look at
// the other workers.
happyWorker = workerThread->worker();
break;
}
else
{
busyThreads++;
if ( ( !happyWorker && workerThread && workerThread->worker() ) ||
( workerThread && workerThread->worker() && workerThread->worker()->outstandingJobs() < happyWorker->outstandingJobs() ) )
if ( !happyWorker )
{
// Case 2: We have not yet got a happyWorker but the current
// workerThread has a worker so use it as a fallback.
happyWorker = workerThread->worker();
}
else if ( workerThread->worker()->outstandingJobs() < happyWorker->outstandingJobs() )
{
// Case 3: We have a worker and the current worker is less busy
// than the previous minimum.
happyWorker = workerThread->worker();
}
}
}
tDebug( LOGVERBOSE ) << "Enqueueing command to thread:" << happyWorker << busyThreads << lc->commandname();
Q_ASSERT( happyWorker );