Skip to content
Permalink
Browse files

Add method to force a detach for QgsSpatialIndex

Since the underlying libspatialindex is not thread safe
on some platforms (e.g. Windows), manual calls to detach()
must be made if a QgsSpatialIndex is to be accessed across
multiple threads.

Note that for platforms on which libspatialindex is thread
safe, calling detach() has no effect and does not force the
deep copy.
  • Loading branch information
nyalldawson committed Feb 9, 2018
1 parent 98d43ea commit abcaba857f50d9c2149eb29c3369915b423b06f1
Showing with 36 additions and 0 deletions.
  1. +14 −0 python/core/qgsspatialindex.sip.in
  2. +8 −0 src/core/qgsspatialindex.cpp
  3. +14 −0 src/core/qgsspatialindex.h
@@ -60,6 +60,20 @@ Copy constructor
~QgsSpatialIndex();


void detach();
%Docstring
Detaches the index, forcing a deep copy of the underlying
spatial index data.

Since the underlying libspatialindex is not thread safe on some platforms (e.g. Windows),
manual calls to detach() must be made if a QgsSpatialIndex is to be accessed across multiple threads.

Note that for platforms on which libspatialindex is thread safe, calling
detach() has no effect and does not force the deep copy.

.. versionadded:: 3.0
%End


bool insertFeature( const QgsFeature &f );
%Docstring
@@ -266,6 +266,14 @@ QgsSpatialIndex &QgsSpatialIndex::operator=( const QgsSpatialIndex &other )
return *this;
}

void QgsSpatialIndex::detach()
{
// libspatialindex is not thread safe on windows - so force the deep copy
#if defined(Q_OS_WIN)
d.detach();
#endif
}

SpatialIndex::Region QgsSpatialIndex::rectToRegion( const QgsRectangle &rect )
{
double pt1[2] = { rect.xMinimum(), rect.yMinimum() },
@@ -97,6 +97,20 @@ class CORE_EXPORT QgsSpatialIndex
//! Implement assignment operator
QgsSpatialIndex &operator=( const QgsSpatialIndex &other );

/**
* Detaches the index, forcing a deep copy of the underlying
* spatial index data.
*
* Since the underlying libspatialindex is not thread safe on some platforms (e.g. Windows),
* manual calls to detach() must be made if a QgsSpatialIndex is to be accessed across multiple threads.
*
* Note that for platforms on which libspatialindex is thread safe, calling
* detach() has no effect and does not force the deep copy.
*
* \since QGIS 3.0
*/
void detach();

/* operations */

//! Add feature to index

0 comments on commit abcaba8

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