Skip to content

Commit

Permalink
Fix qgstaskmanager waitforfinished so it waits that the task was
Browse files Browse the repository at this point in the history
actually started
  • Loading branch information
troopa81 authored and nyalldawson committed Oct 30, 2019
1 parent 92102bd commit 0a80236
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/qgstaskmanager.cpp
Expand Up @@ -29,6 +29,7 @@ QgsTask::QgsTask( const QString &name, Flags flags )
: mFlags( flags )
, mDescription( name )
{
mNotStartedMutex.lock();
}

QgsTask::~QgsTask()
Expand All @@ -41,6 +42,7 @@ QgsTask::~QgsTask()
delete subTask.task;
}
mNotFinishedMutex.unlock();
mNotStartedMutex.unlock();
}

void QgsTask::setDescription( const QString &description )
Expand All @@ -55,6 +57,7 @@ qint64 QgsTask::elapsedTime() const

void QgsTask::start()
{
mNotStartedMutex.unlock();
mNotFinishedMutex.lock();
mStartCount++;
Q_ASSERT( mStartCount == 1 );
Expand Down Expand Up @@ -152,6 +155,9 @@ QList<QgsMapLayer *> QgsTask::dependentLayers() const

bool QgsTask::waitForFinished( int timeout )
{
// We wait the task to be started
mNotStartedMutex.lock();

bool rv = true;
if ( mOverallStatus == Complete || mOverallStatus == Terminated )
{
Expand Down
1 change: 1 addition & 0 deletions src/core/qgstaskmanager.h
Expand Up @@ -310,6 +310,7 @@ class CORE_EXPORT QgsTask : public QObject
* it's used as a trigger for waitForFinished.
*/
QMutex mNotFinishedMutex;
QMutex mNotStartedMutex;

//! Progress of this (parent) task alone
double mProgress = 0.0;
Expand Down

0 comments on commit 0a80236

Please sign in to comment.