Skip to content
Permalink
Browse files

Make the task manager cancel operation thread-safe

  • Loading branch information
troopa81 authored and nyalldawson committed Feb 12, 2020
1 parent 722a41e commit 046b1e8996d1703a25b5d8989e4735f336cb66ab
Showing with 10 additions and 4 deletions.
  1. +8 −0 src/core/qgstaskmanager.cpp
  2. +2 −1 src/core/qgstaskmanager.h
  3. +0 −3 tests/src/core/testqgstaskmanager.cpp
@@ -91,7 +91,9 @@ void QgsTask::cancel()
if ( mOverallStatus == Complete || mOverallStatus == Terminated )
return;

mShouldTerminateMutex.lock();
mShouldTerminate = true;
mShouldTerminateMutex.unlock();
if ( mStatus == Queued || mStatus == OnHold )
{
// immediately terminate unstarted jobs
@@ -111,6 +113,12 @@ void QgsTask::cancel()
}
}

bool QgsTask::isCanceled() const
{
QMutexLocker locker( &mShouldTerminateMutex );
return mShouldTerminate;
}

void QgsTask::hold()
{
if ( mStatus == Queued )
@@ -283,7 +283,7 @@ class CORE_EXPORT QgsTask : public QObject
* flag, then derived classes' run() methods should periodically check this and
* terminate in a safe manner.
*/
bool isCanceled() const { return mShouldTerminate; }
bool isCanceled() const;

protected slots:

@@ -323,6 +323,7 @@ class CORE_EXPORT QgsTask : public QObject
//! Overall progress of this task and all subtasks
double mTotalProgress = 0.0;
bool mShouldTerminate = false;
mutable QMutex mShouldTerminateMutex;
int mStartCount = 0;

struct SubTask
@@ -133,9 +133,6 @@ class CancelableTask : public QgsTask
~CancelableTask() override
{
qDebug() << "deleting task " << description();

int i = 1;
i++;
}

protected:

0 comments on commit 046b1e8

Please sign in to comment.
You can’t perform that action at this time.