Skip to content
Permalink
Browse files

prevent concurrent access while creating iterators and updating cache…

… info (#3224)

#mutexmania
kudos to @m-kuhn
  • Loading branch information
3nids authored and m-kuhn committed Jun 21, 2016
1 parent b443627 commit 7eacd444d0524bd57cea68b78af6aa11243025b6
@@ -2211,6 +2211,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

QgsAttributeTableConfig mAttributeTableConfig;

QMutex mFeatureSourceConstructorMutex;

friend class QgsVectorLayerFeatureSource;
};

@@ -29,6 +29,7 @@
QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( QgsVectorLayer *layer )
: mCrsId( 0 )
{
QMutexLocker locker( &layer->mFeatureSourceConstructorMutex );
mProviderFeatureSource = layer->dataProvider()->featureSource();
mFields = layer->fields();

@@ -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.
@@ -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 )
{
@@ -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 )
{
@@ -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.
You can’t perform that action at this time.