diff --git a/src/core/geometry/qgsgeos.cpp b/src/core/geometry/qgsgeos.cpp index c6e32610b76..9b088253012 100644 --- a/src/core/geometry/qgsgeos.cpp +++ b/src/core/geometry/qgsgeos.cpp @@ -98,7 +98,12 @@ static void printGEOSNotice( const char *fmt, ... ) // QgsGeosContext // +#if defined(USE_THREAD_LOCAL) && !defined(Q_OS_WIN) thread_local QgsGeosContext QgsGeosContext::sGeosContext; +#else +QThreadStorage< QgsGeosContext * > QgsGeosContext::sGeosContext; +#endif + QgsGeosContext::QgsGeosContext() { @@ -122,7 +127,21 @@ QgsGeosContext::~QgsGeosContext() GEOSContextHandle_t QgsGeosContext::get() { +#if defined(USE_THREAD_LOCAL) && !defined(Q_OS_WIN) return sGeosContext.mContext; +#else + GEOSContextHandle_t gContext = nullptr; + if ( sGeosContext.hasLocalData() ) + { + gContext = sGeosContext.localData()->mContext; + } + else + { + sGeosContext.setLocalData( new QgsGeosContext() ); + gContext = sGeosContext.localData()->mContext; + } + return gContext; +#endif } // diff --git a/src/core/geometry/qgsgeos.h b/src/core/geometry/qgsgeos.h index 92ad193c315..81cf9b78086 100644 --- a/src/core/geometry/qgsgeos.h +++ b/src/core/geometry/qgsgeos.h @@ -21,6 +21,7 @@ email : marco.hugentobler at sourcepole dot com #include "qgis_core.h" #include "qgsgeometryengine.h" #include "qgsgeometry.h" +#include "qgsconfig.h" #include class QgsLineString; @@ -28,6 +29,9 @@ class QgsPolygon; class QgsGeometry; class QgsGeometryCollection; +#if !defined(USE_THREAD_LOCAL) || defined(Q_OS_WIN) +#include +#endif /** * \class QgsGeosContext @@ -55,7 +59,12 @@ class CORE_EXPORT QgsGeosContext * Thread local GEOS context storage. A new GEOS context will be created * for every thread. */ + +#if defined(USE_THREAD_LOCAL) && !defined(Q_OS_WIN) static thread_local QgsGeosContext sGeosContext; +#else + static QThreadStorage< QgsGeosContext * > sGeosContext; +#endif }; /**