Skip to content

Commit

Permalink
Rename some static variables to use 's' prefix
Browse files Browse the repository at this point in the history
To match QGIS code conventions
  • Loading branch information
nyalldawson committed Nov 23, 2017
1 parent e0bdd26 commit 5b66ea7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
86 changes: 43 additions & 43 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -94,16 +94,16 @@ static bool IsLocalFile( const QString &path );
static const QByteArray ORIG_OGC_FID = "orig_ogc_fid";
QMutex QgsOgrProviderUtils::globalMutex( QMutex::Recursive );
QMutex QgsOgrProviderUtils::sGlobalMutex( QMutex::Recursive );
QMap< QgsOgrProviderUtils::DatasetIdentification,
QList<QgsOgrProviderUtils::DatasetWithLayers *> > QgsOgrProviderUtils::mapSharedDS;
QList<QgsOgrProviderUtils::DatasetWithLayers *> > QgsOgrProviderUtils::sMapSharedDS;
QMap< QString, int > QgsOgrProviderUtils::mapCountOpenedDS;
QMap< QString, int > QgsOgrProviderUtils::sMapCountOpenedDS;
QMap< GDALDatasetH, bool> QgsOgrProviderUtils::mapDSHandleToUpdateMode;
QMap< GDALDatasetH, bool> QgsOgrProviderUtils::sMapDSHandleToUpdateMode;
QMap< QString, QDateTime > QgsOgrProviderUtils::mapDSNameToLastModifiedDate;
QMap< QString, QDateTime > QgsOgrProviderUtils::sMapDSNameToLastModifiedDate;
bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
{
Expand Down Expand Up @@ -3398,9 +3398,9 @@ GDALDatasetH QgsOgrProviderUtils::GDALOpenWrapper( const char *pszPath, bool bUp
GDALDriverH hDrv = GDALGetDatasetDriver( hDS );
if ( bIsLocalGpkg && strcmp( GDALGetDriverShortName( hDrv ), "GPKG" ) == 0 )
{
QMutexLocker locker( &globalMutex );
mapCountOpenedDS[ filePath ]++;
mapDSHandleToUpdateMode[ hDS ] = bUpdate;
QMutexLocker locker( &sGlobalMutex );
sMapCountOpenedDS[ filePath ]++;
sMapDSHandleToUpdateMode[ hDS ] = bUpdate;
}
if ( phDriver )
*phDriver = hDrv;
Expand Down Expand Up @@ -3460,15 +3460,15 @@ void QgsOgrProviderUtils::GDALCloseWrapper( GDALDatasetH hDS )
bool openedAsUpdate = false;
bool tryReturnToWall = false;
{
QMutexLocker locker( &globalMutex );
mapCountOpenedDS[ datasetName ] --;
if ( mapCountOpenedDS[ datasetName ] == 0 )
QMutexLocker locker( &sGlobalMutex );
sMapCountOpenedDS[ datasetName ] --;
if ( sMapCountOpenedDS[ datasetName ] == 0 )
{
mapCountOpenedDS.remove( datasetName );
openedAsUpdate = mapDSHandleToUpdateMode[hDS];
sMapCountOpenedDS.remove( datasetName );
openedAsUpdate = sMapDSHandleToUpdateMode[hDS];
tryReturnToWall = true;
}
mapDSHandleToUpdateMode.remove( hDS );
sMapDSHandleToUpdateMode.remove( hDS );
}
if ( tryReturnToWall )
{
Expand Down Expand Up @@ -4121,15 +4121,15 @@ static GDALDatasetH OpenHelper( const QString &dsName,

void QgsOgrProviderUtils::invalidateCachedDatasets( const QString &dsName )
{
QMutexLocker locker( &globalMutex );
QMutexLocker locker( &sGlobalMutex );
while ( true )
{
bool erased = false;
for ( auto iter = mapSharedDS.begin(); iter != mapSharedDS.end(); ++iter )
for ( auto iter = sMapSharedDS.begin(); iter != sMapSharedDS.end(); ++iter )
{
if ( iter.key().dsName == dsName )
{
mapSharedDS.erase( iter );
sMapSharedDS.erase( iter );
erased = true;
break;
}
Expand All @@ -4143,8 +4143,8 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
int layerIndex,
QString &errCause )
{
QMutexLocker locker( &globalMutex );
for ( auto iter = mapSharedDS.begin(); iter != mapSharedDS.end(); ++iter )
QMutexLocker locker( &sGlobalMutex );
for ( auto iter = sMapSharedDS.begin(); iter != sMapSharedDS.end(); ++iter )
{
if ( iter.key().dsName == dsName )
{
Expand Down Expand Up @@ -4184,7 +4184,7 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
int layerIndex,
QString &errCause )
{
QMutexLocker locker( &globalMutex );
QMutexLocker locker( &sGlobalMutex );

// The idea is that we want to minimize the number of GDALDatasetH
// handles openeded. But we have constraints. We do not want that 2
Expand All @@ -4197,8 +4197,8 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
ident.options = options;
// Find if there's a list of DatasetWithLayers* that match our
// (dsName, updateMode, options) criteria
auto iter = mapSharedDS.find( ident );
if ( iter != mapSharedDS.end() )
auto iter = sMapSharedDS.find( ident );
if ( iter != sMapSharedDS.end() )
{
// Browse through this list, to look for a DatasetWithLayers*
// instance that don't use yet our layer of interest
Expand Down Expand Up @@ -4254,7 +4254,7 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,

QList<DatasetWithLayers *> datasetList;
datasetList.push_back( ds );
mapSharedDS[ident] = datasetList;
sMapSharedDS[ident] = datasetList;

return layer;
}
Expand All @@ -4263,9 +4263,9 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
const QString &layerName,
QString &errCause )
{
QMutexLocker locker( &globalMutex );
QMutexLocker locker( &sGlobalMutex );

for ( auto iter = mapSharedDS.begin(); iter != mapSharedDS.end(); ++iter )
for ( auto iter = sMapSharedDS.begin(); iter != sMapSharedDS.end(); ++iter )
{
if ( iter.key().dsName == dsName )
{
Expand Down Expand Up @@ -4319,10 +4319,10 @@ static QDateTime getLastModified( const QString &dsName )
// decrement the cache modified date, so that the file appears newer to it
void QgsOgrProviderUtils::invalidateCachedLastModifiedDate( const QString &dsName )
{
QMutexLocker locker( &globalMutex );
QMutexLocker locker( &sGlobalMutex );

auto iter = mapDSNameToLastModifiedDate.find( dsName );
if ( iter != mapDSNameToLastModifiedDate.end() )
auto iter = sMapDSNameToLastModifiedDate.find( dsName );
if ( iter != sMapDSNameToLastModifiedDate.end() )
{
QgsDebugMsg( QString( "invalidating last modified date for %1" ).arg( dsName ) );
iter.value() = iter.value().addSecs( -10 );
Expand Down Expand Up @@ -4353,8 +4353,8 @@ QString QgsOgrProviderUtils::expandAuthConfig( const QString &dsName )
// Must be called under the globalMutex
bool QgsOgrProviderUtils::canUseOpenedDatasets( const QString &dsName )
{
auto iter = mapDSNameToLastModifiedDate.find( dsName );
if ( iter == mapDSNameToLastModifiedDate.end() )
auto iter = sMapDSNameToLastModifiedDate.find( dsName );
if ( iter == sMapDSNameToLastModifiedDate.end() )
return true;
return getLastModified( dsName ) <= iter.value();
}
Expand All @@ -4366,7 +4366,7 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
const QString &layerName,
QString &errCause )
{
QMutexLocker locker( &globalMutex );
QMutexLocker locker( &sGlobalMutex );

// The idea is that we want to minimize the number of GDALDatasetH
// handles openeded. But we have constraints. We do not want that 2
Expand All @@ -4379,18 +4379,18 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
ident.options = options;
// Find if there's a list of DatasetWithLayers* that match our
// (dsName, updateMode, options) criteria
auto iter = mapSharedDS.find( ident );
if ( iter != mapSharedDS.end() )
auto iter = sMapSharedDS.find( ident );
if ( iter != sMapSharedDS.end() )
{
if ( !canUseOpenedDatasets( dsName ) )
{
QgsDebugMsg( QString( "Cannot reuse existing opened dataset(s) on %1 since it has been modified" ).arg( dsName ) );
invalidateCachedDatasets( dsName );
iter = mapSharedDS.find( ident );
Q_ASSERT( iter == mapSharedDS.end() );
iter = sMapSharedDS.find( ident );
Q_ASSERT( iter == sMapSharedDS.end() );
}
}
if ( iter != mapSharedDS.end() )
if ( iter != sMapSharedDS.end() )
{
// Browse through this list, to look for a DatasetWithLayers*
// instance that don't use yet our layer of interest
Expand Down Expand Up @@ -4430,7 +4430,7 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
errCause = QObject::tr( "Cannot open %1." ).arg( dsName );
return nullptr;
}
mapDSNameToLastModifiedDate[dsName] = getLastModified( dsName );
sMapDSNameToLastModifiedDate[dsName] = getLastModified( dsName );

OGRLayerH hLayer = GDALDatasetGetLayerByName(
hDS, layerName.toUtf8().constData() );
Expand Down Expand Up @@ -4460,7 +4460,7 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
errCause = QObject::tr( "Cannot open %1." ).arg( dsName );
return nullptr;
}
mapDSNameToLastModifiedDate[dsName] = getLastModified( dsName );
sMapDSNameToLastModifiedDate[dsName] = getLastModified( dsName );

OGRLayerH hLayer = GDALDatasetGetLayerByName(
hDS, layerName.toUtf8().constData() );
Expand All @@ -4481,7 +4481,7 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,

QList<DatasetWithLayers *> datasetList;
datasetList.push_back( ds );
mapSharedDS[ident] = datasetList;
sMapSharedDS[ident] = datasetList;

return layer;
}
Expand All @@ -4502,7 +4502,7 @@ void QgsOgrProviderUtils::release( QgsOgrLayer *&layer )
if ( !layer )
return;

QMutexLocker locker( &globalMutex );
QMutexLocker locker( &sGlobalMutex );

if ( !layer->isSqlLayer )
{
Expand All @@ -4521,8 +4521,8 @@ void QgsOgrProviderUtils::release( QgsOgrLayer *&layer )

if ( !layer->isSqlLayer )
{
auto iter = mapSharedDS.find( layer->ident );
if ( iter != mapSharedDS.end() )
auto iter = sMapSharedDS.find( layer->ident );
if ( iter != sMapSharedDS.end() )
{
auto &datasetList = iter.value();
int i = 0;
Expand All @@ -4540,7 +4540,7 @@ void QgsOgrProviderUtils::release( QgsOgrLayer *&layer )
}

if ( datasetList.isEmpty() )
mapSharedDS.erase( iter );
sMapSharedDS.erase( iter );
}
}
QgsOgrProviderUtils::GDALCloseWrapper( layer->ds->hDS );
Expand Down
10 changes: 5 additions & 5 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -346,19 +346,19 @@ class QgsOgrProviderUtils
};

//! Global mutex for QgsOgrProviderUtils
static QMutex globalMutex;
static QMutex sGlobalMutex;

//! Map dataset identification to a list of corresponding DatasetWithLayers*
static QMap< DatasetIdentification, QList<DatasetWithLayers *> > mapSharedDS;
static QMap< DatasetIdentification, QList<DatasetWithLayers *> > sMapSharedDS;

//! Map a dataset name to the number of opened GDAL dataset objects on it (if opened with GDALOpenWrapper, only for GPKG)
static QMap< QString, int > mapCountOpenedDS;
static QMap< QString, int > sMapCountOpenedDS;

//! Map a dataset handle to its update open mode (if opened with GDALOpenWrapper, only for GPKG)
static QMap< GDALDatasetH, bool> mapDSHandleToUpdateMode;
static QMap< GDALDatasetH, bool> sMapDSHandleToUpdateMode;

//! Map a dataset name to its last modified data
static QMap< QString, QDateTime > mapDSNameToLastModifiedDate;
static QMap< QString, QDateTime > sMapDSNameToLastModifiedDate;

static bool canUseOpenedDatasets( const QString &dsName );

Expand Down

0 comments on commit 5b66ea7

Please sign in to comment.