1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-17 19:37:09 +02:00

Safer thread stopping, should fix an assert

This commit is contained in:
Jeff Mitchell
2013-01-16 14:50:03 -05:00
parent c1ea6d7ea1
commit 0c68f55937
3 changed files with 58 additions and 27 deletions

View File

@@ -34,9 +34,6 @@
#include "utils/Logger.h" #include "utils/Logger.h"
using namespace Tomahawk;
void void
DirLister::go() DirLister::go()
{ {
@@ -100,6 +97,38 @@ DirLister::scanDir( QDir dir, int depth )
} }
DirListerThreadController::DirListerThreadController( QObject *parent )
: QThread( parent )
{
tDebug() << Q_FUNC_INFO;
}
DirListerThreadController::~DirListerThreadController()
{
tDebug() << Q_FUNC_INFO;
}
void
DirListerThreadController::run()
{
m_dirLister = QPointer< DirLister >( new DirLister( m_paths ) );
connect( m_dirLister.data(), SIGNAL( fileToScan( QFileInfo ) ),
parent(), SLOT( scanFile( QFileInfo ) ), Qt::QueuedConnection );
// queued, so will only fire after all dirs have been scanned:
connect( m_dirLister.data(), SIGNAL( finished() ),
parent(), SLOT( postOps() ), Qt::QueuedConnection );
QMetaObject::invokeMethod( m_dirLister.data(), "go", Qt::QueuedConnection );
exec();
if( !m_dirLister.isNull() )
delete m_dirLister.data();
}
MusicScanner::MusicScanner( ScanManager::ScanMode scanMode, const QStringList& paths, quint32 bs ) MusicScanner::MusicScanner( ScanManager::ScanMode scanMode, const QStringList& paths, quint32 bs )
: QObject() : QObject()
, m_scanMode( scanMode ) , m_scanMode( scanMode )
@@ -125,12 +154,11 @@ MusicScanner::~MusicScanner()
{ {
tDebug() << Q_FUNC_INFO; tDebug() << Q_FUNC_INFO;
if ( !m_dirLister.isNull() ) if ( m_dirListerThreadController )
{ {
m_dirListerThreadController->quit();; m_dirListerThreadController->quit();
m_dirListerThreadController->wait( 60000 ); m_dirListerThreadController->wait( 60000 );
delete m_dirLister.data();
delete m_dirListerThreadController; delete m_dirListerThreadController;
m_dirListerThreadController = 0; m_dirListerThreadController = 0;
} }
@@ -182,20 +210,9 @@ MusicScanner::scan()
return; return;
} }
m_dirListerThreadController = new QThread( this ); m_dirListerThreadController = new DirListerThreadController( this );
m_dirListerThreadController->setPaths( m_paths );
m_dirLister = QPointer< DirLister >( new DirLister( m_paths ) );
m_dirLister.data()->moveToThread( m_dirListerThreadController );
connect( m_dirLister.data(), SIGNAL( fileToScan( QFileInfo ) ),
SLOT( scanFile( QFileInfo ) ), Qt::QueuedConnection );
// queued, so will only fire after all dirs have been scanned:
connect( m_dirLister.data(), SIGNAL( finished() ),
SLOT( postOps() ), Qt::QueuedConnection );
m_dirListerThreadController->start( QThread::IdlePriority ); m_dirListerThreadController->start( QThread::IdlePriority );
QMetaObject::invokeMethod( m_dirLister.data(), "go" );
} }
@@ -250,12 +267,11 @@ MusicScanner::postOps()
void void
MusicScanner::cleanup() MusicScanner::cleanup()
{ {
if ( !m_dirLister.isNull() ) if ( m_dirListerThreadController )
{ {
m_dirListerThreadController->quit();; m_dirListerThreadController->quit();
m_dirListerThreadController->wait( 60000 ); m_dirListerThreadController->wait( 60000 );
delete m_dirLister.data();
delete m_dirListerThreadController; delete m_dirListerThreadController;
m_dirListerThreadController = 0; m_dirListerThreadController = 0;
} }
@@ -368,7 +384,7 @@ MusicScanner::readFile( const QFileInfo& fi )
int bitrate = 0; int bitrate = 0;
int duration = 0; int duration = 0;
Tag *tag = Tag::fromFile( f ); Tomahawk::Tag *tag = Tomahawk::Tag::fromFile( f );
if ( f.audioProperties() ) if ( f.audioProperties() )
{ {
TagLib::AudioProperties *properties = f.audioProperties(); TagLib::AudioProperties *properties = f.audioProperties();
@@ -414,3 +430,4 @@ MusicScanner::readFile( const QFileInfo& fi )
m_scanned++; m_scanned++;
return m; return m;
} }

View File

@@ -79,6 +79,21 @@ private:
bool m_deleting; bool m_deleting;
}; };
class DirListerThreadController : public QThread
{
Q_OBJECT
public:
DirListerThreadController( QObject* parent );
virtual ~DirListerThreadController();
void setPaths( const QStringList& paths ) { m_paths = paths; }
void run();
private:
QPointer< DirLister > m_dirLister;
QStringList m_paths;
};
class MusicScanner : public QObject class MusicScanner : public QObject
{ {
@@ -125,8 +140,7 @@ private:
QVariantList m_filesToDelete; QVariantList m_filesToDelete;
quint32 m_batchsize; quint32 m_batchsize;
QPointer< DirLister > m_dirLister; DirListerThreadController* m_dirListerThreadController;
QThread* m_dirListerThreadController;
}; };
#endif #endif

View File

@@ -123,7 +123,7 @@ InfoSystem::~InfoSystem()
{ {
tDebug() << Q_FUNC_INFO << " beginning"; tDebug() << Q_FUNC_INFO << " beginning";
if ( m_infoSystemWorkerThreadController->worker() ) if ( m_infoSystemWorkerThreadController )
{ {
m_infoSystemWorkerThreadController->quit(); m_infoSystemWorkerThreadController->quit();
m_infoSystemWorkerThreadController->wait( 60000 ); m_infoSystemWorkerThreadController->wait( 60000 );
@@ -133,7 +133,7 @@ InfoSystem::~InfoSystem()
} }
tDebug() << Q_FUNC_INFO << " done deleting worker"; tDebug() << Q_FUNC_INFO << " done deleting worker";
if( m_infoSystemCacheThreadController->cache() ) if( m_infoSystemCacheThreadController )
{ {
m_infoSystemCacheThreadController->quit(); m_infoSystemCacheThreadController->quit();
m_infoSystemCacheThreadController->wait( 60000 ); m_infoSystemCacheThreadController->wait( 60000 );