diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index 06e4b8d0a..7100c8dd5 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -19,6 +19,7 @@ #include "ScriptCommandQueue.h" #include +#include ScriptCommandQueue::ScriptCommandQueue( QObject* parent ) : QObject( parent ) @@ -31,7 +32,10 @@ ScriptCommandQueue::ScriptCommandQueue( QObject* parent ) void ScriptCommandQueue::enqueue( const QSharedPointer< ScriptCommand >& req ) { + QMutexLocker locker( &m_mutex ); m_queue.append( req ); + locker.unlock(); + if ( m_queue.count() == 1 ) nextCommand(); } @@ -61,9 +65,10 @@ ScriptCommandQueue::onCommandDone() { m_timer->stop(); + QMutexLocker locker( &m_mutex ); const QSharedPointer< ScriptCommand > req = m_queue.first(); - m_queue.removeAll( req ); + locker.unlock(); disconnect( req.data(), SIGNAL( done() ), this, SLOT( onCommandDone() ) ); @@ -80,10 +85,12 @@ ScriptCommandQueue::onTimeout() { m_timer->stop(); + QMutexLocker locker( &m_mutex ); const QSharedPointer< ScriptCommand > req = m_queue.first(); + m_queue.removeAll( req ); + locker.unlock(); req->reportFailure(); - m_queue.removeAll( req ); disconnect( req.data(), SIGNAL( done() ), this, SLOT( onCommandDone() ) ); diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.h b/src/libtomahawk/resolvers/ScriptCommandQueue.h index a233ccf44..aa137ab82 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.h +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.h @@ -25,6 +25,7 @@ #include #include #include +#include class ScriptCommandQueue : public QObject { @@ -43,6 +44,7 @@ private slots: private: QQueue< QSharedPointer< ScriptCommand > > m_queue; QTimer* m_timer; + QMutex m_mutex; }; Q_DECLARE_METATYPE( QSharedPointer< ScriptCommand > )