mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Simplify QgsTask::waitForFinished, hopefully fix bugs
This commit is contained in:
parent
28fa839a08
commit
9b4be7ae64
@ -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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user