mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-17 03:24:15 +02:00
Safer thread stopping, should fix an assert
This commit is contained in:
@@ -34,9 +34,6 @@
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
void
|
||||
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 )
|
||||
: QObject()
|
||||
, m_scanMode( scanMode )
|
||||
@@ -125,12 +154,11 @@ MusicScanner::~MusicScanner()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
|
||||
if ( !m_dirLister.isNull() )
|
||||
if ( m_dirListerThreadController )
|
||||
{
|
||||
m_dirListerThreadController->quit();;
|
||||
m_dirListerThreadController->quit();
|
||||
m_dirListerThreadController->wait( 60000 );
|
||||
|
||||
delete m_dirLister.data();
|
||||
delete m_dirListerThreadController;
|
||||
m_dirListerThreadController = 0;
|
||||
}
|
||||
@@ -182,20 +210,9 @@ MusicScanner::scan()
|
||||
return;
|
||||
}
|
||||
|
||||
m_dirListerThreadController = new QThread( this );
|
||||
|
||||
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 = new DirListerThreadController( this );
|
||||
m_dirListerThreadController->setPaths( m_paths );
|
||||
m_dirListerThreadController->start( QThread::IdlePriority );
|
||||
QMetaObject::invokeMethod( m_dirLister.data(), "go" );
|
||||
}
|
||||
|
||||
|
||||
@@ -250,12 +267,11 @@ MusicScanner::postOps()
|
||||
void
|
||||
MusicScanner::cleanup()
|
||||
{
|
||||
if ( !m_dirLister.isNull() )
|
||||
if ( m_dirListerThreadController )
|
||||
{
|
||||
m_dirListerThreadController->quit();;
|
||||
m_dirListerThreadController->quit();
|
||||
m_dirListerThreadController->wait( 60000 );
|
||||
|
||||
delete m_dirLister.data();
|
||||
delete m_dirListerThreadController;
|
||||
m_dirListerThreadController = 0;
|
||||
}
|
||||
@@ -368,7 +384,7 @@ MusicScanner::readFile( const QFileInfo& fi )
|
||||
int bitrate = 0;
|
||||
int duration = 0;
|
||||
|
||||
Tag *tag = Tag::fromFile( f );
|
||||
Tomahawk::Tag *tag = Tomahawk::Tag::fromFile( f );
|
||||
if ( f.audioProperties() )
|
||||
{
|
||||
TagLib::AudioProperties *properties = f.audioProperties();
|
||||
@@ -414,3 +430,4 @@ MusicScanner::readFile( const QFileInfo& fi )
|
||||
m_scanned++;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@@ -79,6 +79,21 @@ private:
|
||||
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
|
||||
{
|
||||
@@ -125,8 +140,7 @@ private:
|
||||
QVariantList m_filesToDelete;
|
||||
quint32 m_batchsize;
|
||||
|
||||
QPointer< DirLister > m_dirLister;
|
||||
QThread* m_dirListerThreadController;
|
||||
DirListerThreadController* m_dirListerThreadController;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -123,7 +123,7 @@ InfoSystem::~InfoSystem()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << " beginning";
|
||||
|
||||
if ( m_infoSystemWorkerThreadController->worker() )
|
||||
if ( m_infoSystemWorkerThreadController )
|
||||
{
|
||||
m_infoSystemWorkerThreadController->quit();
|
||||
m_infoSystemWorkerThreadController->wait( 60000 );
|
||||
@@ -133,7 +133,7 @@ InfoSystem::~InfoSystem()
|
||||
}
|
||||
tDebug() << Q_FUNC_INFO << " done deleting worker";
|
||||
|
||||
if( m_infoSystemCacheThreadController->cache() )
|
||||
if( m_infoSystemCacheThreadController )
|
||||
{
|
||||
m_infoSystemCacheThreadController->quit();
|
||||
m_infoSystemCacheThreadController->wait( 60000 );
|
||||
|
Reference in New Issue
Block a user