CFileHasher* CFileHasher::HashFile(CSharedFilePtr pFile) { m_pSection.lock(); if(m_pHashers == 0) { m_nMaxHashers = qMin<quint32>(4, qMax<quint32>(2, QThread::idealThreadCount())); m_pHashers = new CFileHasher*[m_nMaxHashers]; for(uint i = 0; i < m_nMaxHashers; i++) { m_pHashers[i] = 0; } } //qDebug() << "File" << pFile->m_sFilename << "queued for hashing"; m_lQueue.enqueue(pFile); CFileHasher* pHasher = 0; if(m_nRunningHashers < (uint)m_lQueue.size() && m_nRunningHashers < m_nMaxHashers) { for(uint i = 0; i < m_nMaxHashers; i++) { if(!m_pHashers[i]) { systemLog.postLog(LogSeverity::Debug, QString("Starting hasher: %1").arg(m_nRunningHashers)); //qDebug() << "Starting hasher: " << m_nRunningHashers; m_pHashers[i] = new CFileHasher(); connect(m_pHashers[i], SIGNAL(QueueEmpty()), &ShareManager, SLOT(RunHashing()), Qt::UniqueConnection); connect(m_pHashers[i], SIGNAL(FileHashed(CSharedFilePtr)), &ShareManager, SLOT(OnFileHashed(CSharedFilePtr)), Qt::UniqueConnection); m_pHashers[i]->start((quazaaSettings.Library.HighPriorityHashing ? QThread::NormalPriority : QThread::LowestPriority)); m_nRunningHashers++; pHasher = m_pHashers[i]; break; } } } m_pSection.unlock(); CFileHasher::m_oWaitCond.wakeOne(); return pHasher; }
FileHasher* FileHasher::hashFile( SharedFilePtr pFile ) { m_pSection.lock(); if ( m_pHashers == 0 ) { m_nMaxHashers = qMin<quint32>( 4, qMax<quint32>( 2, QThread::idealThreadCount() ) ); m_pHashers = new FileHasher*[m_nMaxHashers]; for ( uint i = 0; i < m_nMaxHashers; i++ ) { m_pHashers[i] = 0; } } //qDebug() << "File" << pFile->m_sFilename << "queued for hashing"; m_lQueue.enqueue( pFile ); FileHasher* pHasher = 0; if ( m_nRunningHashers < ( uint )m_lQueue.size() && m_nRunningHashers < m_nMaxHashers ) { for ( uint i = 0; i < m_nMaxHashers; i++ ) { if ( !m_pHashers[i] ) { systemLog.postLog( LogSeverity::Debug, QString( "Starting hasher: %1" ).arg( m_nRunningHashers ) ); m_pHashers[i] = new FileHasher(); pHasher = m_pHashers[i]; pHasher->m_nId = i; connect( pHasher, SIGNAL( queueEmpty() ), &shareManager, SLOT( RunHashing() ), Qt::UniqueConnection ); connect( pHasher, SIGNAL( fileHashed( SharedFilePtr ) ), &shareManager, SLOT( OnFileHashed( SharedFilePtr ) ), Qt::UniqueConnection ); connect( pHasher, SIGNAL( hasherStarted( int ) ), &shareManager, SIGNAL( hasherStarted( int ) ) ); connect( pHasher, SIGNAL( hasherFinished( int ) ), &shareManager, SIGNAL( hasherFinished( int ) ) ); connect( pHasher, SIGNAL( hashingProgress( int, QString, double, int ) ), &shareManager, SIGNAL( hashingProgress( int, QString, double, int ) ) ); m_pHashers[i]->start( ( quazaaSettings.Library.HighPriorityHashing ? QThread::NormalPriority : QThread::LowestPriority ) ); m_nRunningHashers++; break; } } }