Use QThreadStorage for GEOS context on windows

This commit is contained in:
Nyall Dawson 2024-04-11 11:18:10 +10:00
parent 3d31ba4d39
commit 018c844828
2 changed files with 28 additions and 0 deletions

View File

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

View File

@ -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 <geos_c.h>
class QgsLineString;
@ -28,6 +29,9 @@ class QgsPolygon;
class QgsGeometry;
class QgsGeometryCollection;
#if !defined(USE_THREAD_LOCAL) || defined(Q_OS_WIN)
#include <QThreadStorage>
#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
};
/**