Skip to content
Permalink
Browse files

Fix crashes with parallel access to GRASS vectors

  • Loading branch information
wonder-sk committed Apr 27, 2014
1 parent 48c3b99 commit 40b20f6b0f25ed26a2180290d6c6d07b35144346
Showing with 15 additions and 0 deletions.
  1. +8 −0 src/providers/grass/qgsgrassfeatureiterator.cpp
  2. +7 −0 src/providers/grass/qgsgrassfeatureiterator.h
@@ -62,9 +62,15 @@ void copy_boxlist_and_destroy( struct boxlist *blist, struct ilist * list )
}
#endif


QMutex QgsGrassFeatureIterator::sMutex;


QgsGrassFeatureIterator::QgsGrassFeatureIterator( QgsGrassFeatureSource* source, bool ownSource, const QgsFeatureRequest& request )
: QgsAbstractFeatureIteratorFromSource( source, ownSource, request )
{
sMutex.lock();

// Init structures
mPoints = Vect_new_line_struct();
mCats = Vect_new_cats_struct();
@@ -344,6 +350,8 @@ bool QgsGrassFeatureIterator::close()

free( mSelection );

sMutex.unlock();

mClosed = true;
return true;
}
@@ -17,6 +17,7 @@

#include "qgsfeatureiterator.h"

#include <QMutex>

class QgsGrassProvider;

@@ -111,6 +112,12 @@ class QgsGrassFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsG
* @param map pointer to map structure
*/
void allocateSelection( struct Map_info *map );

//! Mutex that protects GRASS library from parallel access from multiple iterators at once.
//! The library uses static/global variables in various places when accessing vector data,
//! making it non-reentrant and thus impossible to use from multiple threads.
//! (e.g. static LocList in Vect_select_lines_by_box, global BranchBuf in RTreeGetBranches)
static QMutex sMutex;
};

#endif // QGSGRASSFEATUREITERATOR_H

0 comments on commit 40b20f6

Please sign in to comment.
You can’t perform that action at this time.