Skip to content

Commit 7eacd44

Browse files
3nidsm-kuhn
authored andcommittedJun 21, 2016
prevent concurrent access while creating iterators and updating cache info (#3224)
#mutexmania kudos to @m-kuhn
1 parent b443627 commit 7eacd44

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed
 

‎src/core/qgsvectorlayer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
22112211

22122212
QgsAttributeTableConfig mAttributeTableConfig;
22132213

2214+
QMutex mFeatureSourceConstructorMutex;
2215+
22142216
friend class QgsVectorLayerFeatureSource;
22152217
};
22162218

‎src/core/qgsvectorlayerfeatureiterator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( QgsVectorLayer *layer )
3030
: mCrsId( 0 )
3131
{
32+
QMutexLocker locker( &layer->mFeatureSourceConstructorMutex );
3233
mProviderFeatureSource = layer->dataProvider()->featureSource();
3334
mFields = layer->fields();
3435

‎src/core/qgsvectorlayerjoinbuffer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static bool _hasCycleDFS( QgsVectorLayer* n, QHash<QgsVectorLayer*, int>& mark )
6262

6363
bool QgsVectorLayerJoinBuffer::addJoin( const QgsVectorJoinInfo& joinInfo )
6464
{
65+
QMutexLocker locker( &mMutex );
6566
mVectorJoins.push_back( joinInfo );
6667

6768
// run depth-first search to detect cycles in the graph of joins between layers.
@@ -97,6 +98,7 @@ bool QgsVectorLayerJoinBuffer::addJoin( const QgsVectorJoinInfo& joinInfo )
9798

9899
bool QgsVectorLayerJoinBuffer::removeJoin( const QString& joinLayerId )
99100
{
101+
QMutexLocker locker( &mMutex );
100102
bool res = false;
101103
for ( int i = 0; i < mVectorJoins.size(); ++i )
102104
{
@@ -259,6 +261,7 @@ void QgsVectorLayerJoinBuffer::updateFields( QgsFields& fields )
259261

260262
void QgsVectorLayerJoinBuffer::createJoinCaches()
261263
{
264+
QMutexLocker locker( &mMutex );
262265
QList< QgsVectorJoinInfo >::iterator joinIt = mVectorJoins.begin();
263266
for ( ; joinIt != mVectorJoins.end(); ++joinIt )
264267
{

‎src/core/qgsvectorlayerjoinbuffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject
101101

102102
/** Caches attributes of join layer in memory if QgsVectorJoinInfo.memoryCache is true (and the cache is not already there)*/
103103
void cacheJoinLayer( QgsVectorJoinInfo& joinInfo );
104+
105+
/** Main mutex to protect most data members that can be modified concurrently */
106+
QMutex mMutex;
104107
};
105108

106109
#endif // QGSVECTORLAYERJOINBUFFER_H

0 commit comments

Comments
 (0)
Please sign in to comment.