Skip to content

Commit 505e365

Browse files
committedNov 9, 2017
[WFS provider] Fix deadlock when adding WFS layer to project from Python console (fixes #17087)
1 parent 309b1c8 commit 505e365

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed
 

‎src/providers/wfs/qgswfsfeatureiterator.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,25 @@ void QgsWFSThreadedFeatureDownloader::stop()
759759
}
760760
}
761761

762+
void QgsWFSThreadedFeatureDownloader::startAndWait()
763+
{
764+
start();
765+
766+
QMutexLocker locker( &mWaitMutex );
767+
while ( !mDownloader )
768+
{
769+
mWaitCond.wait( &mWaitMutex );
770+
}
771+
}
772+
762773
void QgsWFSThreadedFeatureDownloader::run()
763774
{
764775
// We need to construct it in the run() method (i.e. in the new thread)
765776
mDownloader = new QgsWFSFeatureDownloader( mShared );
766-
emit ready();
777+
{
778+
QMutexLocker locker( &mWaitMutex );
779+
mWaitCond.wakeOne();
780+
}
767781
mDownloader->run( true, /* serialize features */
768782
0 /* user max features */ );
769783
}

‎src/providers/wfs/qgswfsfeatureiterator.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <QProgressDialog>
2626
#include <QPushButton>
27+
#include <QMutex>
28+
#include <QWaitCondition>
2729

2830
class QgsWFSProvider;
2931
class QgsWFSSharedData;
@@ -164,20 +166,20 @@ class QgsWFSThreadedFeatureDownloader: public QThread
164166
/** Return downloader object */
165167
QgsWFSFeatureDownloader* downloader() { return mDownloader; }
166168

167-
/** Stops (synchronously) the download */
168-
void stop();
169-
170-
signals:
171-
/** Emitted when the thread is ready */
172-
void ready();
169+
//! Starts thread and wait for it to be started
170+
void startAndWait();
173171

172+
//! Stops (synchronously) the download
173+
void stop();
174174
protected:
175175
/** Inherited from QThread. Starts the download */
176176
void run() override;
177177

178178
private:
179179
QgsWFSSharedData* mShared; //!< Mutable data shared between provider and feature sources
180180
QgsWFSFeatureDownloader* mDownloader;
181+
QWaitCondition mWaitCond;
182+
QMutex mWaitMutex;
181183
};
182184

183185
class QgsWFSFeatureSource;

‎src/providers/wfs/qgswfsshareddata.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,7 @@ int QgsWFSSharedData::registerToCache( QgsWFSFeatureIterator* iterator, QgsRecta
553553
mDownloadFinished = false;
554554
mComputedExtent = QgsRectangle();
555555
mDownloader = new QgsWFSThreadedFeatureDownloader( this );
556-
QEventLoop loop;
557-
connect( mDownloader, SIGNAL( ready() ), &loop, SLOT( quit() ) );
558-
mDownloader->start();
559-
loop.exec( QEventLoop::ExcludeUserInputEvents );
556+
mDownloader->startAndWait();
560557
}
561558
if ( mDownloadFinished )
562559
return -1;

0 commit comments

Comments
 (0)
Please sign in to comment.