Skip to content
Permalink
Browse files
Fix race
  • Loading branch information
nyalldawson committed Jul 1, 2021
1 parent 7dec305 commit ced5910bc8da3a18e037b382ca43c61a88adc10c
@@ -48,11 +48,14 @@ specified ``uri``.
Returns the sublayer details as calculated by the task.
%End

virtual bool run();

virtual void cancel();


protected:

virtual bool run();


};

/************************************************************************
@@ -19,6 +19,7 @@
#include "qgsfeedback.h"
#include "qgsproviderregistry.h"
#include "qgsprovidersublayerdetails.h"
#include "qgsreadwritelocker.h"

QgsProviderSublayerTask::QgsProviderSublayerTask( const QString &uri )
: QgsTask( tr( "Retrieving layers" ), QgsTask::CanCancel | QgsTask::CancelWithoutPrompt )
@@ -28,6 +29,7 @@ QgsProviderSublayerTask::QgsProviderSublayerTask( const QString &uri )

QList<QgsProviderSublayerDetails> QgsProviderSublayerTask::results() const
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );
return mResults;
}

@@ -37,7 +39,11 @@ bool QgsProviderSublayerTask::run()
{
mFeedback = std::make_unique< QgsFeedback >();

mResults = QgsProviderRegistry::instance()->querySublayers( mUri, Qgis::SublayerQueryFlag::ResolveGeometryType | Qgis::SublayerQueryFlag::CountFeatures, mFeedback.get() );
const QList<QgsProviderSublayerDetails> res = QgsProviderRegistry::instance()->querySublayers( mUri, Qgis::SublayerQueryFlag::ResolveGeometryType | Qgis::SublayerQueryFlag::CountFeatures, mFeedback.get() );

QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );
mResults = res;

return true;
}

@@ -19,6 +19,7 @@
#define QGSPROVIDERSUBLAYERTASKTASK_H

#include "qgstaskmanager.h"
#include <QReadWriteLock>
#include <memory>

class QgsFeedback;
@@ -61,9 +62,12 @@ class CORE_EXPORT QgsProviderSublayerTask : public QgsTask
*/
QList<QgsProviderSublayerDetails> results() const;

bool run() override;
void cancel() override;

protected:

bool run() override;

private:

QString mUri;
@@ -72,6 +76,8 @@ class CORE_EXPORT QgsProviderSublayerTask : public QgsTask

QList<QgsProviderSublayerDetails> mResults;

mutable QReadWriteLock mLock;

};

#endif // QGSPROVIDERSUBLAYERTASKTASK_H

0 comments on commit ced5910

Please sign in to comment.