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.
This commit is contained in:
Nyall Dawson 2018-02-06 16:23:56 +10:00
parent 98d43ea4e8
commit abcaba857f
3 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -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() },

View File

@ -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