mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 05:37:29 +02:00
Create QThread subclasses for InfoSystemWorker and InfoSystemCache, so we don't try to delete them from a different thread (illegal in Qt), instead delete from QThread subclass' destructor.
This commit is contained in:
@@ -58,14 +58,14 @@ InfoSystem::InfoSystem( QObject *parent )
|
|||||||
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_infoSystemCacheThreadController = new QThread( this );
|
m_infoSystemCacheThreadController = new InfoSystemCacheThread( this );
|
||||||
m_cache = QWeakPointer< InfoSystemCache >( new InfoSystemCache() );
|
m_cache = m_infoSystemCacheThreadController->cache();
|
||||||
m_cache.data()->moveToThread( m_infoSystemCacheThreadController );
|
//m_cache.data()->moveToThread( m_infoSystemCacheThreadController );
|
||||||
m_infoSystemCacheThreadController->start( QThread::IdlePriority );
|
m_infoSystemCacheThreadController->start( QThread::IdlePriority );
|
||||||
|
|
||||||
m_infoSystemWorkerThreadController = new QThread( this );
|
m_infoSystemWorkerThreadController = new InfoSystemWorkerThread( this );
|
||||||
m_worker = QWeakPointer< InfoSystemWorker>( new InfoSystemWorker() );
|
m_worker = m_infoSystemWorkerThreadController->worker();
|
||||||
m_worker.data()->moveToThread( m_infoSystemWorkerThreadController );
|
//m_worker.data()->moveToThread( m_infoSystemWorkerThreadController );
|
||||||
m_infoSystemWorkerThreadController->start();
|
m_infoSystemWorkerThreadController->start();
|
||||||
|
|
||||||
QMetaObject::invokeMethod( m_worker.data(), "init", Qt::QueuedConnection, Q_ARG( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >, m_cache ) );
|
QMetaObject::invokeMethod( m_worker.data(), "init", Qt::QueuedConnection, Q_ARG( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >, m_cache ) );
|
||||||
@@ -89,7 +89,7 @@ InfoSystem::~InfoSystem()
|
|||||||
m_infoSystemWorkerThreadController->quit();
|
m_infoSystemWorkerThreadController->quit();
|
||||||
m_infoSystemWorkerThreadController->wait( 60000 );
|
m_infoSystemWorkerThreadController->wait( 60000 );
|
||||||
|
|
||||||
delete m_worker.data();
|
//delete m_worker.data();
|
||||||
delete m_infoSystemWorkerThreadController;
|
delete m_infoSystemWorkerThreadController;
|
||||||
m_infoSystemWorkerThreadController = 0;
|
m_infoSystemWorkerThreadController = 0;
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ InfoSystem::~InfoSystem()
|
|||||||
m_infoSystemCacheThreadController->quit();
|
m_infoSystemCacheThreadController->quit();
|
||||||
m_infoSystemCacheThreadController->wait( 60000 );
|
m_infoSystemCacheThreadController->wait( 60000 );
|
||||||
|
|
||||||
delete m_cache.data();
|
//delete m_cache.data();
|
||||||
delete m_infoSystemCacheThreadController;
|
delete m_infoSystemCacheThreadController;
|
||||||
m_infoSystemCacheThreadController = 0;
|
m_infoSystemCacheThreadController = 0;
|
||||||
}
|
}
|
||||||
@@ -155,6 +155,54 @@ InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input )
|
|||||||
QMetaObject::invokeMethod( m_worker.data(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input[ type ] ) );
|
QMetaObject::invokeMethod( m_worker.data(), "pushInfo", Qt::QueuedConnection, Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QVariant, input[ type ] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
InfoSystemCacheThread::InfoSystemCacheThread( QObject *parent )
|
||||||
|
: QThread( parent )
|
||||||
|
{
|
||||||
|
m_cache = QWeakPointer< InfoSystemCache >( new InfoSystemCache() );
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoSystemCacheThread::~InfoSystemCacheThread()
|
||||||
|
{
|
||||||
|
delete m_cache.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoSystemCacheThread::InfoSystemCacheThread::run()
|
||||||
|
{
|
||||||
|
exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
QWeakPointer< InfoSystemCache >
|
||||||
|
InfoSystemCacheThread::cache() const
|
||||||
|
{
|
||||||
|
return m_cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoSystemWorkerThread::InfoSystemWorkerThread( QObject *parent )
|
||||||
|
: QThread( parent )
|
||||||
|
{
|
||||||
|
m_worker = QWeakPointer< InfoSystemWorker >( new InfoSystemWorker() );
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoSystemWorkerThread::~InfoSystemWorkerThread()
|
||||||
|
{
|
||||||
|
delete m_worker.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoSystemWorkerThread::InfoSystemWorkerThread::run()
|
||||||
|
{
|
||||||
|
exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
QWeakPointer< InfoSystemWorker >
|
||||||
|
InfoSystemWorkerThread::worker() const
|
||||||
|
{
|
||||||
|
return m_worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} //namespace InfoSystem
|
} //namespace InfoSystem
|
||||||
|
|
||||||
} //namespace Tomahawk
|
} //namespace Tomahawk
|
||||||
|
@@ -159,6 +159,36 @@ private:
|
|||||||
|
|
||||||
typedef QWeakPointer< InfoPlugin > InfoPluginPtr;
|
typedef QWeakPointer< InfoPlugin > InfoPluginPtr;
|
||||||
|
|
||||||
|
class InfoSystemCacheThread : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
InfoSystemCacheThread( QObject *parent );
|
||||||
|
virtual ~InfoSystemCacheThread();
|
||||||
|
|
||||||
|
void run();
|
||||||
|
QWeakPointer< InfoSystemCache > cache() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWeakPointer< InfoSystemCache > m_cache;
|
||||||
|
};
|
||||||
|
|
||||||
|
class InfoSystemWorkerThread : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
InfoSystemWorkerThread( QObject *parent );
|
||||||
|
virtual ~InfoSystemWorkerThread();
|
||||||
|
|
||||||
|
void run();
|
||||||
|
QWeakPointer< InfoSystemWorker > worker() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWeakPointer< InfoSystemWorker > m_worker;
|
||||||
|
};
|
||||||
|
|
||||||
class DLLEXPORT InfoSystem : public QObject
|
class DLLEXPORT InfoSystem : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -185,8 +215,8 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
QWeakPointer< InfoSystemCache > m_cache;
|
QWeakPointer< InfoSystemCache > m_cache;
|
||||||
QWeakPointer< InfoSystemWorker > m_worker;
|
QWeakPointer< InfoSystemWorker > m_worker;
|
||||||
QThread* m_infoSystemCacheThreadController;
|
InfoSystemCacheThread* m_infoSystemCacheThreadController;
|
||||||
QThread* m_infoSystemWorkerThreadController;
|
InfoSystemWorkerThread* m_infoSystemWorkerThreadController;
|
||||||
|
|
||||||
static InfoSystem* s_instance;
|
static InfoSystem* s_instance;
|
||||||
};
|
};
|
||||||
@@ -195,6 +225,8 @@ private:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline uint qHash( Tomahawk::InfoSystem::InfoCriteriaHash hash )
|
inline uint qHash( Tomahawk::InfoSystem::InfoCriteriaHash hash )
|
||||||
{
|
{
|
||||||
QCryptographicHash md5( QCryptographicHash::Md5 );
|
QCryptographicHash md5( QCryptographicHash::Md5 );
|
||||||
|
Reference in New Issue
Block a user