Skip to content

Commit

Permalink
prevent concurrent access while creating iterators and updating cache…
Browse files Browse the repository at this point in the history
… info (#3224)

#mutexmania
kudos to @m-kuhn
  • Loading branch information
3nids authored and m-kuhn committed Jun 21, 2016
1 parent b443627 commit 7eacd44
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -2211,6 +2211,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

QgsAttributeTableConfig mAttributeTableConfig;

QMutex mFeatureSourceConstructorMutex;

friend class QgsVectorLayerFeatureSource;
};

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -29,6 +29,7 @@
QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( QgsVectorLayer *layer )
: mCrsId( 0 )
{
QMutexLocker locker( &layer->mFeatureSourceConstructorMutex );
mProviderFeatureSource = layer->dataProvider()->featureSource();
mFields = layer->fields();

Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayerjoinbuffer.cpp
Expand Up @@ -62,6 +62,7 @@ static bool _hasCycleDFS( QgsVectorLayer* n, QHash<QgsVectorLayer*, int>& mark )

bool QgsVectorLayerJoinBuffer::addJoin( const QgsVectorJoinInfo& joinInfo )
{
QMutexLocker locker( &mMutex );
mVectorJoins.push_back( joinInfo );

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

bool QgsVectorLayerJoinBuffer::removeJoin( const QString& joinLayerId )
{
QMutexLocker locker( &mMutex );
bool res = false;
for ( int i = 0; i < mVectorJoins.size(); ++i )
{
Expand Down Expand Up @@ -259,6 +261,7 @@ void QgsVectorLayerJoinBuffer::updateFields( QgsFields& fields )

void QgsVectorLayerJoinBuffer::createJoinCaches()
{
QMutexLocker locker( &mMutex );
QList< QgsVectorJoinInfo >::iterator joinIt = mVectorJoins.begin();
for ( ; joinIt != mVectorJoins.end(); ++joinIt )
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayerjoinbuffer.h
Expand Up @@ -101,6 +101,9 @@ class CORE_EXPORT QgsVectorLayerJoinBuffer : public QObject

/** Caches attributes of join layer in memory if QgsVectorJoinInfo.memoryCache is true (and the cache is not already there)*/
void cacheJoinLayer( QgsVectorJoinInfo& joinInfo );

/** Main mutex to protect most data members that can be modified concurrently */
QMutex mMutex;
};

#endif // QGSVECTORLAYERJOINBUFFER_H

0 comments on commit 7eacd44

Please sign in to comment.