mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Properly fix deletion of worker and cache objects in separate threads that are not the GUI thread.
This commit is contained in:
@@ -59,13 +59,15 @@ InfoSystem::InfoSystem( QObject *parent )
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_infoSystemCacheThreadController = new InfoSystemCacheThread( this );
|
m_infoSystemCacheThreadController = new InfoSystemCacheThread( this );
|
||||||
m_cache = m_infoSystemCacheThreadController->cache();
|
m_cache = QWeakPointer< InfoSystemCache >( new InfoSystemCache() );
|
||||||
//m_cache.data()->moveToThread( m_infoSystemCacheThreadController );
|
m_cache.data()->moveToThread( m_infoSystemCacheThreadController );
|
||||||
|
m_infoSystemCacheThreadController->setCache( m_cache );
|
||||||
m_infoSystemCacheThreadController->start( QThread::IdlePriority );
|
m_infoSystemCacheThreadController->start( QThread::IdlePriority );
|
||||||
|
|
||||||
m_infoSystemWorkerThreadController = new InfoSystemWorkerThread( this );
|
m_infoSystemWorkerThreadController = new InfoSystemWorkerThread( this );
|
||||||
m_worker = m_infoSystemWorkerThreadController->worker();
|
m_worker = QWeakPointer< InfoSystemWorker >( new InfoSystemWorker() );
|
||||||
//m_worker.data()->moveToThread( m_infoSystemWorkerThreadController );
|
m_worker.data()->moveToThread( m_infoSystemWorkerThreadController );
|
||||||
|
m_infoSystemWorkerThreadController->setWorker( m_worker );
|
||||||
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 ) );
|
||||||
@@ -159,7 +161,6 @@ InfoSystem::pushInfo( const QString &caller, const InfoTypeMap &input )
|
|||||||
InfoSystemCacheThread::InfoSystemCacheThread( QObject *parent )
|
InfoSystemCacheThread::InfoSystemCacheThread( QObject *parent )
|
||||||
: QThread( parent )
|
: QThread( parent )
|
||||||
{
|
{
|
||||||
m_cache = QWeakPointer< InfoSystemCache >( new InfoSystemCache() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoSystemCacheThread::~InfoSystemCacheThread()
|
InfoSystemCacheThread::~InfoSystemCacheThread()
|
||||||
@@ -179,21 +180,27 @@ InfoSystemCacheThread::cache() const
|
|||||||
return m_cache;
|
return m_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoSystemCacheThread::setCache( QWeakPointer< InfoSystemCache > cache )
|
||||||
|
{
|
||||||
|
m_cache = cache;
|
||||||
|
}
|
||||||
|
|
||||||
InfoSystemWorkerThread::InfoSystemWorkerThread( QObject *parent )
|
InfoSystemWorkerThread::InfoSystemWorkerThread( QObject *parent )
|
||||||
: QThread( parent )
|
: QThread( parent )
|
||||||
{
|
{
|
||||||
m_worker = QWeakPointer< InfoSystemWorker >( new InfoSystemWorker() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoSystemWorkerThread::~InfoSystemWorkerThread()
|
InfoSystemWorkerThread::~InfoSystemWorkerThread()
|
||||||
{
|
{
|
||||||
delete m_worker.data();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoSystemWorkerThread::InfoSystemWorkerThread::run()
|
InfoSystemWorkerThread::InfoSystemWorkerThread::run()
|
||||||
{
|
{
|
||||||
exec();
|
exec();
|
||||||
|
if( m_worker )
|
||||||
|
delete m_worker.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWeakPointer< InfoSystemWorker >
|
QWeakPointer< InfoSystemWorker >
|
||||||
@@ -202,6 +209,12 @@ InfoSystemWorkerThread::worker() const
|
|||||||
return m_worker;
|
return m_worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoSystemWorkerThread::setWorker( QWeakPointer< InfoSystemWorker > worker )
|
||||||
|
{
|
||||||
|
m_worker = worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} //namespace InfoSystem
|
} //namespace InfoSystem
|
||||||
|
|
||||||
|
@@ -169,6 +169,7 @@ public:
|
|||||||
|
|
||||||
void run();
|
void run();
|
||||||
QWeakPointer< InfoSystemCache > cache() const;
|
QWeakPointer< InfoSystemCache > cache() const;
|
||||||
|
void setCache( QWeakPointer< InfoSystemCache > cache );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWeakPointer< InfoSystemCache > m_cache;
|
QWeakPointer< InfoSystemCache > m_cache;
|
||||||
@@ -184,6 +185,7 @@ public:
|
|||||||
|
|
||||||
void run();
|
void run();
|
||||||
QWeakPointer< InfoSystemWorker > worker() const;
|
QWeakPointer< InfoSystemWorker > worker() const;
|
||||||
|
void setWorker( QWeakPointer< InfoSystemWorker > worker );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWeakPointer< InfoSystemWorker > m_worker;
|
QWeakPointer< InfoSystemWorker > m_worker;
|
||||||
|
Reference in New Issue
Block a user