Skip to content
Permalink
Browse files

Simplify QgsTask::waitForFinished, hopefully fix bugs

  • Loading branch information
nyalldawson committed Aug 7, 2018
1 parent 28fa839 commit 9b4be7ae64debba4aa016c1d880cac55a2e26a66
Showing with 13 additions and 11 deletions.
  1. +1 −1 python/core/auto_generated/qgstaskmanager.sip.in
  2. +11 −7 src/core/qgstaskmanager.cpp
  3. +1 −3 src/core/qgstaskmanager.h
@@ -178,7 +178,7 @@ be canceled if any of these layers are about to be removed.
.. seealso:: :py:func:`setDependentLayers`
%End

bool waitForFinished( unsigned long timeout = 30000 );
bool waitForFinished( int timeout = 30000 );
%Docstring
Blocks the current thread until the task finishes or a maximum of ``timeout`` milliseconds.
If ``timeout`` is ``0`` the thread will be blocked forever.
@@ -144,7 +144,7 @@ QList<QgsMapLayer *> QgsTask::dependentLayers() const
return _qgis_listQPointerToRaw( mDependentLayers );
}

bool QgsTask::waitForFinished( unsigned long timeout )
bool QgsTask::waitForFinished( int timeout )
{
bool rv = true;
if ( mOverallStatus == Complete || mOverallStatus == Terminated )
@@ -154,8 +154,16 @@ bool QgsTask::waitForFinished( unsigned long timeout )
else
{
if ( timeout == 0 )
timeout = ULONG_MAX;
rv = mTaskFinished.wait( &mNotFinishedMutex, timeout );
timeout = std::numeric_limits< int >::max();
if ( mNotFinishedMutex.tryLock( timeout ) )
{
mNotFinishedMutex.unlock();
rv = true;
}
else
{
rv = false;
}
}
return rv;
}
@@ -253,9 +261,7 @@ void QgsTask::processSubTasksForCompletion()
setProgress( 100.0 );
emit statusChanged( Complete );
emit taskCompleted();
mTaskFinished.wakeAll();
mNotFinishedMutex.unlock();
mTaskFinished.wakeAll();
}
else if ( mStatus == Complete )
{
@@ -282,9 +288,7 @@ void QgsTask::processSubTasksForTermination()

emit statusChanged( Terminated );
emit taskTerminated();
mTaskFinished.wakeAll();
mNotFinishedMutex.unlock();
mTaskFinished.wakeAll();
}
else if ( mStatus == Terminated && !subTasksTerminated )
{
@@ -204,7 +204,7 @@ class CORE_EXPORT QgsTask : public QObject
*
* The result will be false if the wait timed out and true in any other case.
*/
bool waitForFinished( unsigned long timeout = 30000 );
bool waitForFinished( int timeout = 30000 );

signals:

@@ -312,8 +312,6 @@ class CORE_EXPORT QgsTask : public QObject
bool mShouldTerminate = false;
int mStartCount = 0;

QWaitCondition mTaskFinished;

struct SubTask
{
SubTask( QgsTask *task, const QgsTaskList &dependencies, SubTaskDependency dependency )

0 comments on commit 9b4be7a

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