mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
Do not try to quit DatabaseWorkerThreads where we have never started the event loop
This commit is contained in:
parent
1d0dae488d
commit
1f056c99d3
@ -143,11 +143,17 @@ Database::~Database()
|
||||
delete m_idWorker;
|
||||
|
||||
if ( m_workerRW )
|
||||
{
|
||||
// Ensure event loop was started so quit() has any effect.
|
||||
m_workerRW->waitForEventLoopStart();
|
||||
m_workerRW.data()->quit();
|
||||
}
|
||||
foreach ( QPointer< DatabaseWorkerThread > workerThread, m_workerThreads )
|
||||
{
|
||||
if ( workerThread && workerThread.data()->worker() )
|
||||
workerThread.data()->quit();
|
||||
// Ensure event loop was started so quit() has any effect.
|
||||
workerThread->waitForEventLoopStart();
|
||||
// If event loop already was killed, the following is just a no-op.
|
||||
workerThread->quit();
|
||||
}
|
||||
|
||||
if ( m_workerRW )
|
||||
|
@ -46,6 +46,7 @@ DatabaseWorkerThread::DatabaseWorkerThread( Database* db, bool mutates )
|
||||
, m_db( db )
|
||||
, m_mutates( mutates )
|
||||
{
|
||||
m_startupMutex.lock();
|
||||
}
|
||||
|
||||
|
||||
@ -54,6 +55,7 @@ DatabaseWorkerThread::run()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "DatabaseWorkerThread starting...";
|
||||
m_worker = QPointer< DatabaseWorker >( new DatabaseWorker( m_db, m_mutates ) );
|
||||
m_startupMutex.unlock();
|
||||
exec();
|
||||
tDebug() << Q_FUNC_INFO << "DatabaseWorkerThread finishing...";
|
||||
if ( m_worker )
|
||||
@ -73,6 +75,15 @@ DatabaseWorkerThread::worker() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseWorkerThread::waitForEventLoopStart()
|
||||
{
|
||||
m_startupMutex.lock();
|
||||
// no-op just to block on locking.
|
||||
m_startupMutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
DatabaseWorker::DatabaseWorker( Database* db, bool mutates )
|
||||
: QObject()
|
||||
, m_db( db )
|
||||
|
@ -70,6 +70,13 @@ public:
|
||||
|
||||
QPointer< DatabaseWorker > worker() const;
|
||||
|
||||
/**
|
||||
* Waits until the event loop was started.
|
||||
*
|
||||
* Blocking, i.e. do not call from within the DatabaseWorkerThread thread.
|
||||
*/
|
||||
void waitForEventLoopStart();
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
@ -77,6 +84,11 @@ private:
|
||||
QPointer< DatabaseWorker > m_worker;
|
||||
Database* m_db;
|
||||
bool m_mutates;
|
||||
|
||||
/**
|
||||
* Locks until we've started the event loop.
|
||||
*/
|
||||
QMutex m_startupMutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user