Skip to content

Commit

Permalink
Fix crashes with parallel access to GRASS vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 27, 2014
1 parent 48c3b99 commit 40b20f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/providers/grass/qgsgrassfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -344,6 +350,8 @@ bool QgsGrassFeatureIterator::close()

free( mSelection );

sMutex.unlock();

mClosed = true;
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions src/providers/grass/qgsgrassfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "qgsfeatureiterator.h"

#include <QMutex>

class QgsGrassProvider;

Expand Down Expand Up @@ -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.