11 changes: 7 additions & 4 deletions gdal/frmts/adrg/adrgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "gdal_pam.h"
#include "ogr_spatialref.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "iso8211.h"

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -111,8 +112,8 @@ class ADRGRasterBand : public GDALPamRasterBand
ADRGRasterBand( ADRGDataset *, int );

virtual GDALColorInterp GetColorInterpretation();
virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );

virtual double GetNoDataValue( int *pbSuccess = NULL );

Expand Down Expand Up @@ -211,9 +212,10 @@ GDALColorInterp ADRGRasterBand::GetColorInterpretation()
/************************************************************************/

CPLErr ADRGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
ADRGDataset* poDS = (ADRGDataset*)this->poDS;
int offset;
int nBlock = nBlockYOff * poDS->NFC + nBlockXOff;
Expand Down Expand Up @@ -256,9 +258,10 @@ CPLErr ADRGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr ADRGRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
ADRGDataset* poDS = (ADRGDataset*)this->poDS;
int offset;
int nBlock = nBlockYOff * poDS->NFC + nBlockXOff;
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/adrg/srpdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "gdal_pam.h"
#include "ogr_spatialref.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "iso8211.h"

// Uncomment to recognize also .gen files in addition to .img files
Expand Down Expand Up @@ -108,7 +109,7 @@ class SRPRasterBand : public GDALPamRasterBand
public:
SRPRasterBand( SRPDataset *, int );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );

virtual double GetNoDataValue( int *pbSuccess = NULL );

Expand Down Expand Up @@ -180,9 +181,10 @@ GDALColorTable *SRPRasterBand::GetColorTable()
/************************************************************************/

CPLErr SRPRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
SRPDataset* poDS = (SRPDataset*)this->poDS;
int offset;
int nBlock = nBlockYOff * poDS->NFC + nBlockXOff;
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/aigrid/aigdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "gdal_pam.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "ogr_spatialref.h"
#include "gdal_rat.h"
#include "aigrid.h"
Expand Down Expand Up @@ -97,7 +98,7 @@ class AIGRasterBand : public GDALPamRasterBand

AIGRasterBand( AIGDataset *, int );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual double GetMinimum( int *pbSuccess );
virtual double GetMaximum( int *pbSuccess );
virtual double GetNoDataValue( int *pbSuccess );
Expand Down Expand Up @@ -145,9 +146,10 @@ AIGRasterBand::AIGRasterBand( AIGDataset *poDS, int nBand )
/************************************************************************/

CPLErr AIGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
AIGDataset *poODS = (AIGDataset *) poDS;
GInt32 *panGridRaster;
int i;
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/airsar/airsardataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "cpl_string.h"
#include "cpl_conv.h"
#include "cpl_vsi.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -84,7 +85,7 @@ class AirSARRasterBand : public GDALPamRasterBand
AirSARRasterBand( AirSARDataset *, int );
virtual ~AirSARRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
};

/* locations of stokes matrix values within padfMatrix ... same order as they
Expand Down Expand Up @@ -174,9 +175,10 @@ AirSARRasterBand::~AirSARRasterBand()
/************************************************************************/

CPLErr AirSARRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
CPLErr eErr;
float *pafLine = (float *) pImage;
int iPixel;
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/blx/blxdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "gdal_pam.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -74,7 +75,7 @@ class BLXRasterBand : public GDALPamRasterBand
virtual int GetOverviewCount();
virtual GDALRasterBand *GetOverview( int );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex );
};

GDALDataset *BLXDataset::Open( GDALOpenInfo * poOpenInfo )
Expand Down Expand Up @@ -234,9 +235,10 @@ GDALRasterBand *BLXRasterBand::GetOverview( int i )
}

CPLErr BLXRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
BLXDataset *poGDS = (BLXDataset *) poDS;

if(blx_readcell(poGDS->blxcontext, nBlockYOff, nBlockXOff, (short *)pImage, nBlockXSize*nBlockYSize*2, overviewLevel) == NULL) {
Expand Down
27 changes: 17 additions & 10 deletions gdal/frmts/bmp/bmpdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
****************************************************************************/

#include "gdal_pam.h"
#include "cpl_multiproc.h"
#include "cpl_string.h"

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -228,7 +229,7 @@ class BMPDataset : public GDALPamDataset
protected:
virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
void *, int, int, GDALDataType,
int, int *, int, int, int );
int, int *, int, int, int, void ** phMutex = NULL );

public:
BMPDataset();
Expand Down Expand Up @@ -265,8 +266,8 @@ class BMPRasterBand : public GDALPamRasterBand
BMPRasterBand( BMPDataset *, int );
~BMPRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );
virtual GDALColorInterp GetColorInterpretation();
virtual GDALColorTable *GetColorTable();
CPLErr SetColorTable( GDALColorTable * );
Expand Down Expand Up @@ -320,8 +321,9 @@ BMPRasterBand::~BMPRasterBand()
/************************************************************************/

CPLErr BMPRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
CPLMutexHolderD( phMutex );
BMPDataset *poGDS = (BMPDataset *) poDS;
GUInt32 iScanOffset;
int i;
Expand Down Expand Up @@ -523,8 +525,9 @@ CPLErr BMPRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr BMPRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
CPLMutexHolderD( phMutex );
BMPDataset *poGDS = (BMPDataset *)poDS;
int iInPixel, iOutPixel;
GUInt32 iScanOffset;
Expand Down Expand Up @@ -679,7 +682,7 @@ class BMPComprRasterBand : public BMPRasterBand
BMPComprRasterBand( BMPDataset *, int );
~BMPComprRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
// virtual CPLErr IWriteBlock( int, int, void * );
};

Expand Down Expand Up @@ -859,8 +862,9 @@ BMPComprRasterBand::~BMPComprRasterBand()
/************************************************************************/

CPLErr BMPComprRasterBand::
IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage )
IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage, void **phMutex )
{
CPLMutexHolderD( phMutex );
memcpy( pImage, pabyUncomprBuf +
(poDS->GetRasterYSize() - nBlockYOff - 1) * poDS->GetRasterXSize(),
nBlockXSize );
Expand Down Expand Up @@ -972,20 +976,23 @@ CPLErr BMPDataset::IRasterIO( GDALRWFlag eRWFlag,
void *pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nBandCount, int *panBandMap,
int nPixelSpace, int nLineSpace, int nBandSpace )
int nPixelSpace, int nLineSpace, int nBandSpace,
void ** phMutex )

{
if( nBandCount > 1 )
return GDALDataset::BlockBasedRasterIO(
eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nBandCount, panBandMap, nPixelSpace, nLineSpace, nBandSpace );
nBandCount, panBandMap, nPixelSpace, nLineSpace, nBandSpace,
phMutex );
else
return
GDALDataset::IRasterIO( eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace );
nPixelSpace, nLineSpace, nBandSpace,
phMutex );
}

/************************************************************************/
Expand Down
8 changes: 5 additions & 3 deletions gdal/frmts/bsb/bsbdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "gdal_pam.h"
#include "bsb_read.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "ogr_spatialref.h"

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -95,7 +96,7 @@ class BSBRasterBand : public GDALPamRasterBand
public:
BSBRasterBand( BSBDataset * );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual GDALColorTable *GetColorTable();
virtual GDALColorInterp GetColorInterpretation();
};
Expand Down Expand Up @@ -136,11 +137,12 @@ BSBRasterBand::BSBRasterBand( BSBDataset *poDS )
/************************************************************************/

CPLErr BSBRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
BSBDataset *poGDS = (BSBDataset *) poDS;
BSBDataset *poGDS = (BSBDataset *) poDS;
GByte *pabyScanline = (GByte*) pImage;
CPLMutexHolderD( phMutex );

if( BSBReadScanline( poGDS->psInfo, nBlockYOff, pabyScanline ) )
{
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/ceos/ceosdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "ceosopen.h"
#include "gdal_pam.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -71,7 +72,7 @@ class CEOSRasterBand : public GDALPamRasterBand

CEOSRasterBand( CEOSDataset *, int );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
};


Expand All @@ -96,9 +97,10 @@ CEOSRasterBand::CEOSRasterBand( CEOSDataset *poDS, int nBand )
/************************************************************************/

CPLErr CEOSRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
CEOSDataset *poCEOS_DS = (CEOSDataset *) poDS;

CPLAssert( nBlockXOff == 0 );
Expand Down
16 changes: 10 additions & 6 deletions gdal/frmts/ceos2/sar_ceosdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gdal_priv.h"
#include "rawdataset.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "ogr_srs_api.h"

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -181,7 +182,7 @@ class CCPRasterBand : public GDALPamRasterBand
public:
CCPRasterBand( SAR_CEOSDataset *, int, GDALDataType );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL );
};

/************************************************************************/
Expand All @@ -197,7 +198,7 @@ class PALSARRasterBand : public GDALPamRasterBand
public:
PALSARRasterBand( SAR_CEOSDataset *, int );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL );
};

/************************************************************************/
Expand All @@ -213,7 +214,7 @@ class SAR_CEOSRasterBand : public GDALPamRasterBand
public:
SAR_CEOSRasterBand( SAR_CEOSDataset *, int, GDALDataType );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL );
};

/************************************************************************/
Expand All @@ -238,9 +239,10 @@ SAR_CEOSRasterBand::SAR_CEOSRasterBand( SAR_CEOSDataset *poGDS, int nBand,
/************************************************************************/

CPLErr SAR_CEOSRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
struct CeosSARImageDesc *ImageDesc;
int offset;
GByte *pabyRecord;
Expand Down Expand Up @@ -372,9 +374,10 @@ Im(SVV) = byte(10) ysca/127
*/

CPLErr CCPRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
struct CeosSARImageDesc *ImageDesc;
int offset;
GByte *pabyRecord;
Expand Down Expand Up @@ -518,9 +521,10 @@ PALSARRasterBand::PALSARRasterBand( SAR_CEOSDataset *poGDS, int nBand )
/************************************************************************/

CPLErr PALSARRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
struct CeosSARImageDesc *ImageDesc;
int offset;
GByte *pabyRecord;
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/coasp/coasp_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "cpl_conv.h"
#include "cpl_vsi.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -278,7 +279,7 @@ class COASPRasterBand : public GDALRasterBand {
public:
COASPRasterBand( COASPDataset *poDS, GDALDataType eDataType, int ePol, VSILFILE *fp );
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff,
void *pImage);
void *pImage, void **phMutex);
};

COASPRasterBand::COASPRasterBand( COASPDataset *poDS, GDALDataType eDataType,
Expand All @@ -293,13 +294,14 @@ COASPRasterBand::COASPRasterBand( COASPDataset *poDS, GDALDataType eDataType,
}

CPLErr COASPRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void *pImage )
void *pImage, void **phMutex )
{
if (this->fp == NULL) {
CPLError(CE_Fatal, 1, "file pointer freed unexpectedly\n");
return CE_Fatal;
}

CPLMutexHolderD( phMutex );
/* 8 bytes per pixel: 4 bytes I, 4 bytes Q */
unsigned long nByteNum = poDS->GetRasterXSize() * 8 * nBlockYOff;

Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/cosar/cosar_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "cpl_conv.h"
#include "cpl_vsi.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include <string.h>

/* Various offsets, in bytes */
Expand Down Expand Up @@ -63,7 +64,7 @@ class COSARRasterBand : public GDALRasterBand
int nBurstNumber;
public:
COSARRasterBand(COSARDataset *, unsigned long nRTNB);
virtual CPLErr IReadBlock(int, int, void *);
virtual CPLErr IReadBlock(int, int, void *, void ** phMutex);
};

/*****************************************************************************
Expand All @@ -79,8 +80,9 @@ COSARRasterBand::COSARRasterBand(COSARDataset *pDS, unsigned long nRTNB) {
}

CPLErr COSARRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff,
void *pImage) {
void *pImage, void ** phMutex) {

CPLMutexHolderD( phMutex );
unsigned long nRSFV = 0;
unsigned long nRSLV = 0;
COSARDataset *pCDS = (COSARDataset *) poDS;
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/ctg/ctgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "gdal_pam.h"
#include "ogr_spatialref.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -157,7 +158,7 @@ class CTGRasterBand : public GDALPamRasterBand
CTGRasterBand( CTGDataset *, int );
~CTGRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual double GetNoDataValue( int *pbSuccess = NULL );
virtual char **GetCategoryNames();
};
Expand Down Expand Up @@ -195,9 +196,10 @@ CTGRasterBand::~CTGRasterBand()
/************************************************************************/

CPLErr CTGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
CTGDataset* poGDS = (CTGDataset* ) poDS;

poGDS->ReadImagery();
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/dods/dodsdataset2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "gdal_priv.h" // GDAL
#include "ogr_spatialref.h"
#include "cpl_string.h"
#include "cpl_multproc.h"

using namespace libdap;

Expand Down Expand Up @@ -294,7 +295,7 @@ class DODSRasterBand : public GDALRasterBand

virtual int GetOverviewCount();
virtual GDALRasterBand *GetOverview( int );
virtual CPLErr IReadBlock(int, int, void *);
virtual CPLErr IReadBlock(int, int, void *, void ** phMutex = NULL);
virtual GDALColorInterp GetColorInterpretation();
virtual GDALColorTable *GetColorTable();
virtual CPLErr SetNoDataValue( double );
Expand Down Expand Up @@ -1430,8 +1431,9 @@ void DODSRasterBand::HarvestDAS()
/************************************************************************/

CPLErr
DODSRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage)
DODSRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage, void **phMutex)
{
CPLMutexHolderD( phMutex );
DODSDataset *poDODS = dynamic_cast<DODSDataset *>(poDS);
int nBytesPerPixel = GDALGetDataTypeSize(eDataType) / 8;

Expand Down
11 changes: 7 additions & 4 deletions gdal/frmts/dted/dteddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "dted_api.h"
#include "gdal_pam.h"
#include "ogr_spatialref.h"
#include "cpl_multiproc.h"
#include <algorithm>

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -87,8 +88,8 @@ class DTEDRasterBand : public GDALPamRasterBand

DTEDRasterBand( DTEDDataset *, int );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex );
virtual CPLErr IWriteBlock( int, int, void *, void ** phMutex );

virtual double GetNoDataValue( int *pbSuccess = NULL );

Expand Down Expand Up @@ -126,9 +127,10 @@ DTEDRasterBand::DTEDRasterBand( DTEDDataset *poDS, int nBand )
/************************************************************************/

CPLErr DTEDRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
DTEDDataset *poDTED_DS = (DTEDDataset *) poDS;
int nYSize = poDTED_DS->psDTED->nYSize;
GInt16 *panData;
Expand Down Expand Up @@ -188,9 +190,10 @@ CPLErr DTEDRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr DTEDRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
DTEDDataset *poDTED_DS = (DTEDDataset *) poDS;
GInt16 *panData;

Expand Down
9 changes: 6 additions & 3 deletions gdal/frmts/e00grid/e00griddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "cpl_vsi_virtual.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "ogr_spatialref.h"
#include "gdal_pam.h"

Expand Down Expand Up @@ -131,7 +132,7 @@ class E00GRIDRasterBand : public GDALPamRasterBand

E00GRIDRasterBand( E00GRIDDataset *, int, GDALDataType );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );

virtual double GetNoDataValue( int *pbSuccess = NULL );
virtual const char *GetUnitType();
Expand Down Expand Up @@ -165,7 +166,7 @@ E00GRIDRasterBand::E00GRIDRasterBand( E00GRIDDataset *poDS, int nBand,
/************************************************************************/

CPLErr E00GRIDRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
E00GRIDDataset *poGDS = (E00GRIDDataset *) poDS;
Expand Down Expand Up @@ -208,7 +209,7 @@ CPLErr E00GRIDRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
{
//CPLDebug("E00GRID", "Forward skip to %d from %d", nBlockYOff, poGDS->nLastYOff);
for(i=poGDS->nLastYOff + 1; i < nBlockYOff;i++)
IReadBlock(0, i, pImage);
IReadBlock(0, i, pImage, phMutex);
}

if (nBlockYOff > poGDS->nMaxYOffset)
Expand All @@ -218,6 +219,7 @@ CPLErr E00GRIDRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
poGDS->nMaxYOffset = nBlockYOff;
}

CPLMutexHolderD( phMutex );
const char* pszLine = NULL;
for(i=0;i<nBlockXSize;i++)
{
Expand Down Expand Up @@ -251,6 +253,7 @@ CPLErr E00GRIDRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
vsi_l_offset nPos = poGDS->nDataStart + nLinesToSkip * nBytesPerLine;
VSIFSeekL(poGDS->fp, nPos, SEEK_SET);

CPLMutexHolderD( phMutex );
for(i=0;i<nBlockXSize;i++)
{
if (VSIFReadL(szVal, E00_FLOAT_SIZE, 1, poGDS->fp) != 1)
Expand Down
31 changes: 19 additions & 12 deletions gdal/frmts/ecw/ecwcreatecopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "gdal_ecw.h"
#include "gdaljp2metadata.h"
#include "ogr_spatialref.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -1540,7 +1541,8 @@ class CPL_DLL ECWWriteDataset : public GDALDataset
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nBandCount, int *panBandMap,
int nPixelSpace, int nLineSpace, int nBandSpace);
int nPixelSpace, int nLineSpace, int nBandSpace,
void ** phMutex = NULL);
#endif
};

Expand Down Expand Up @@ -1577,15 +1579,15 @@ class ECWWriteRasterBand : public GDALRasterBand
virtual GDALColorInterp GetColorInterpretation()
{ return eInterp; }

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );

#ifdef OPTIMIZED_FOR_GDALWARP
virtual CPLErr IRasterIO( GDALRWFlag eRWFlag,
int nXOff, int nYOff, int nXSize, int nYSize,
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nPixelSpace, int nLineSpace);
int nPixelSpace, int nLineSpace, void **phMutex = NULL);
#endif
};

Expand Down Expand Up @@ -1817,7 +1819,8 @@ CPLErr ECWWriteDataset::IRasterIO( GDALRWFlag eRWFlag,
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nBandCount, int *panBandMap,
int nPixelSpace, int nLineSpace, int nBandSpace)
int nPixelSpace, int nLineSpace, int nBandSpace,
void ** phMutex)
{
ECWWriteRasterBand* po4thBand = NULL;
IRasterIORequest* poIORequest = NULL;
Expand Down Expand Up @@ -1857,13 +1860,13 @@ CPLErr ECWWriteDataset::IRasterIO( GDALRWFlag eRWFlag,
for(int iBand = 0; iBand < nBandCount; iBand ++)
{
GetRasterBand(panBandMap[iBand])->WriteBlock(0, iY + nYOff,
pabyData + iY * nLineSpace + iBand * nBandSpace);
pabyData + iY * nLineSpace + iBand * nBandSpace, phMutex);
}

if( poIORequest != NULL )
{
po4thBand->WriteBlock(0, iY + nYOff,
poIORequest->pabyData + iY * nDataTypeSize * nXSize);
poIORequest->pabyData + iY * nDataTypeSize * nXSize, phMutex);
}
}

Expand All @@ -1881,7 +1884,8 @@ CPLErr ECWWriteDataset::IRasterIO( GDALRWFlag eRWFlag,
pData, nBufXSize, nBufYSize,
eBufType,
nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace);
nPixelSpace, nLineSpace, nBandSpace,
phMutex);
}
#endif

Expand Down Expand Up @@ -1928,9 +1932,10 @@ ECWWriteRasterBand::~ECWWriteRasterBand()
/************************************************************************/

CPLErr ECWWriteRasterBand::IReadBlock( int nBlockX, int nBlockY,
void *pBuffer )
void *pBuffer, void **phMutex )

{
CPLMutexHolderD( phMutex );
int nWordSize = GDALGetDataTypeSize( eDataType ) / 8;

// We zero stuff out here, but we can't really read stuff from
Expand All @@ -1950,11 +1955,12 @@ CPLErr ECWWriteRasterBand::IRasterIO( GDALRWFlag eRWFlag,
int nXOff, int nYOff, int nXSize, int nYSize,
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nPixelSpace, int nLineSpace)
int nPixelSpace, int nLineSpace, void ** phMutex)
{
if( eRWFlag == GF_Write && nBand == 4 && poGDS->nBands == 4 &&
poGDS->nPrevIRasterIOBand < 0 )
{
CPLMutexHolderD( phMutex );
/* Triggered when gdalwarp outputs an alpha band */
/* It is called before GDALDatasetRasterIO() on the 3 first bands */
if( poIORequest != NULL )
Expand All @@ -1972,7 +1978,7 @@ CPLErr ECWWriteRasterBand::IRasterIO( GDALRWFlag eRWFlag,
nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize,
eBufType,
nPixelSpace, nLineSpace );
nPixelSpace, nLineSpace, phMutex );
}
#endif

Expand All @@ -1981,9 +1987,10 @@ CPLErr ECWWriteRasterBand::IRasterIO( GDALRWFlag eRWFlag,
/************************************************************************/

CPLErr ECWWriteRasterBand::IWriteBlock( int nBlockX, int nBlockY,
void *pBuffer )
void *pBuffer, void ** phMutex )

{
CPLMutexHolderD( phMutex );
int nWordSize = GDALGetDataTypeSize( eDataType ) / 8;
CPLErr eErr;

Expand Down
38 changes: 24 additions & 14 deletions gdal/frmts/ecw/ecwdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "ogr_spatialref.h"
#include "ogr_api.h"
#include "ogr_geometry.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -827,7 +828,7 @@ CPLErr ECWRasterBand::IRasterIO( GDALRWFlag eRWFlag,
int nXOff, int nYOff, int nXSize, int nYSize,
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nPixelSpace, int nLineSpace )
int nPixelSpace, int nLineSpace, void ** phMutex )
{
if( eRWFlag == GF_Write )
return CE_Failure;
Expand All @@ -848,6 +849,7 @@ CPLErr ECWRasterBand::IRasterIO( GDALRWFlag eRWFlag,
#if !defined(SDK_CAN_DO_SUPERSAMPLING)
if( poGDS->bUseOldBandRasterIOImplementation )
{
CPLMutexHolderD( phMutex );
return OldIRasterIO(eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize,
eBufType,
Expand All @@ -865,14 +867,15 @@ CPLErr ECWRasterBand::IRasterIO( GDALRWFlag eRWFlag,
(nYSize == nRasterYSize) ? poGDS->nRasterYSize : nYSize * nResFactor,
pData, nBufXSize, nBufYSize,
eBufType, 1, &nBand,
nPixelSpace, nLineSpace, nLineSpace*nBufYSize);
nPixelSpace, nLineSpace, nLineSpace*nBufYSize,
phMutex);
}

/************************************************************************/
/* IReadBlock() */
/************************************************************************/

CPLErr ECWRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage )
CPLErr ECWRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage, void ** phMutex )

{
int nXOff = nBlockXOff * nBlockXSize,
Expand All @@ -890,7 +893,7 @@ CPLErr ECWRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage
return IRasterIO( GF_Read,
nXOff, nYOff, nXSize, nYSize,
pImage, nXSize, nYSize,
eDataType, nPixelSpace, nLineSpace );
eDataType, nPixelSpace, nLineSpace, phMutex );
}

/************************************************************************/
Expand Down Expand Up @@ -1762,7 +1765,8 @@ CPLErr ECWDataset::IRasterIO( GDALRWFlag eRWFlag,
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nBandCount, int *panBandMap,
int nPixelSpace, int nLineSpace, int nBandSpace)
int nPixelSpace, int nLineSpace, int nBandSpace,
void ** phMutex)

{
if( eRWFlag == GF_Write )
Expand Down Expand Up @@ -1810,7 +1814,8 @@ CPLErr ECWDataset::IRasterIO( GDALRWFlag eRWFlag,
pData, nBufXSize, nBufYSize,
eBufType,
nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace);
nPixelSpace, nLineSpace, nBandSpace,
phMutex);
}
}
#endif
Expand All @@ -1833,6 +1838,7 @@ CPLErr ECWDataset::IRasterIO( GDALRWFlag eRWFlag,
if( sCachedMultiBandIO.bEnabled &&
sCachedMultiBandIO.pabyData != NULL )
{
CPLMutexHolderD( phMutex );
int j;
int nDataTypeSize = GDALGetDataTypeSize(eBufType) / 8;
for(j = 0; j < nBufYSize; j++)
Expand All @@ -1859,12 +1865,14 @@ CPLErr ECWDataset::IRasterIO( GDALRWFlag eRWFlag,
/* -------------------------------------------------------------------- */
/* Try to do it based on existing "advised" access. */
/* -------------------------------------------------------------------- */
if( TryWinRasterIO( eRWFlag, nXOff, nYOff, nXSize, nYSize,
(GByte *) pData, nBufXSize, nBufYSize,
eBufType, nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace ) )
return CE_None;

{
CPLMutexHolderD( phMutex );
if( TryWinRasterIO( eRWFlag, nXOff, nYOff, nXSize, nYSize,
(GByte *) pData, nBufXSize, nBufYSize,
eBufType, nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace ) )
return CE_None;
}
/* -------------------------------------------------------------------- */
/* If we are requesting a single line at 1:1, we do a multi-band */
/* AdviseRead() and then TryWinRasterIO() again. */
Expand All @@ -1890,7 +1898,8 @@ CPLErr ECWDataset::IRasterIO( GDALRWFlag eRWFlag,
pData, nBufXSize, nBufYSize,
eBufType,
nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace);
nPixelSpace, nLineSpace, nBandSpace,
phMutex);
bUseOldBandRasterIOImplementation = FALSE;
return eErr;
}
Expand All @@ -1903,7 +1912,7 @@ CPLErr ECWDataset::IRasterIO( GDALRWFlag eRWFlag,
//ERO; indeed, the logic could be improved to detect successive pattern of single line reading
//before doing an AdviseRead.
CPLErr eErr;

CPLMutexHolderD( phMutex );
eErr = AdviseRead( nXOff, nYOff, nXSize, GetRasterYSize() - nYOff,
nBufXSize, (nRasterYSize - nYOff) / nYSize, eBufType,
nBandCount, panBandMap, NULL );
Expand Down Expand Up @@ -1931,6 +1940,7 @@ CPLErr ECWDataset::IRasterIO( GDALRWFlag eRWFlag,
anBandIndices[i] = panBandMap[i] - 1;

CleanupWindow();
CPLMutexHolderD( phMutex );

/* -------------------------------------------------------------------- */
/* Cache data in the context of a multi-band reading pattern. */
Expand Down
6 changes: 3 additions & 3 deletions gdal/frmts/ecw/gdal_ecw.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class CPL_DLL ECWDataset : public GDALJP2AbstractDataset

virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
void *, int, int, GDALDataType,
int, int *, int, int, int );
int, int *, int, int, int, void ** phMutex = NULL );

virtual char **GetMetadataDomainList();
virtual const char *GetMetadataItem( const char * pszName,
Expand Down Expand Up @@ -630,14 +630,14 @@ class ECWRasterBand : public GDALPamRasterBand

virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
void *, int, int, GDALDataType,
int, int );
int, int, void ** phMutex = NULL );

public:

ECWRasterBand( ECWDataset *, int, int = -1 );
~ECWRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual int HasArbitraryOverviews() { return apoOverviews.size() == 0; }
virtual int GetOverviewCount() { return (int)apoOverviews.size(); }
virtual GDALRasterBand *GetOverview(int);
Expand Down
11 changes: 7 additions & 4 deletions gdal/frmts/elas/elasdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
****************************************************************************/

#include "gdal_pam.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -126,8 +127,8 @@ class ELASRasterBand : public GDALPamRasterBand

// should override RasterIO eventually.

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL);
virtual CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL);
};


Expand All @@ -154,9 +155,10 @@ ELASRasterBand::ELASRasterBand( ELASDataset *poDS, int nBand )
/************************************************************************/

CPLErr ELASRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
ELASDataset *poGDS = (ELASDataset *) poDS;
CPLErr eErr = CE_None;
long nOffset;
Expand Down Expand Up @@ -189,9 +191,10 @@ CPLErr ELASRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr ELASRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
ELASDataset *poGDS = (ELASDataset *) poDS;
CPLErr eErr = CE_None;
long nOffset;
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/envisat/envisatdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "adsrange.hpp"
#include "rawdataset.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "ogr_srs_api.h"

CPL_CVSID("$Id$");
Expand All @@ -55,7 +56,7 @@ class MerisL2FlagBand : public GDALPamRasterBand
public:
MerisL2FlagBand( GDALDataset *, int, VSILFILE*, off_t, off_t );
virtual ~MerisL2FlagBand();
virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );

private:
off_t nImgOffset;
Expand Down Expand Up @@ -106,10 +107,11 @@ MerisL2FlagBand::~MerisL2FlagBand()
/* IReadBlock() */
/************************************************************************/
CPLErr MerisL2FlagBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
CPLAssert( nBlockXOff == 0 );
CPLAssert( pReadBuf != NULL );
CPLMutexHolderD( phMutex );

off_t nOffset = nImgOffset + nPrefixBytes +
nBlockYOff * nBlockYSize * nRecordSize;
Expand Down
35 changes: 23 additions & 12 deletions gdal/frmts/epsilon/epsilondataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "epsilon.h"
#include "gdal_pam.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -112,7 +113,7 @@ class EpsilonRasterBand : public GDALPamRasterBand
public:
EpsilonRasterBand(EpsilonDataset* poDS, int nBand);

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual GDALColorInterp GetColorInterpretation();
};

Expand Down Expand Up @@ -198,7 +199,7 @@ GDALColorInterp EpsilonRasterBand::GetColorInterpretation()
/************************************************************************/

CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
int nBlockYOff, void * pImage)
int nBlockYOff, void * pImage, void **phMutex)
{
EpsilonDataset* poGDS = (EpsilonDataset*) poDS;

Expand All @@ -223,6 +224,7 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,

if (!poGDS->GetNextBlockData())
{
CPLMutexHolderD( phMutex );
memset(pImage, 0, nBlockXSize * nBlockYSize);
return CE_Failure;
}
Expand All @@ -231,6 +233,7 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
if (eps_read_block_header (poGDS->pabyBlockData,
poGDS->nBlockDataSize, &hdr) != EPS_OK)
{
CPLMutexHolderD( phMutex );
CPLError(CE_Warning, CPLE_AppDefined, "cannot read block header");
memset(pImage, 0, nBlockXSize * nBlockYSize);
return CE_Failure;
Expand All @@ -239,6 +242,7 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
if (hdr.chk_flag == EPS_BAD_CRC ||
hdr.crc_flag == EPS_BAD_CRC)
{
CPLMutexHolderD( phMutex );
CPLError(CE_Warning, CPLE_AppDefined, "bad CRC");
memset(pImage, 0, nBlockXSize * nBlockYSize);
return CE_Failure;
Expand All @@ -250,6 +254,7 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,

if (poGDS->nBands == 1)
{
CPLMutexHolderD( phMutex );
unsigned char ** pTempData =
(unsigned char **) CPLMalloc(h * sizeof(unsigned char*));
for(i=0;i<h;i++)
Expand All @@ -275,13 +280,15 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
(GByte*) VSIMalloc3(nBlockXSize, nBlockYSize, 3);
if (poGDS->pabyRGBData == NULL)
{
CPLMutexHolderD( phMutex );
memset(pImage, 0, nBlockXSize * nBlockYSize);
return CE_Failure;
}
}

if (poGDS->nBufferedBlock == nBlock)
{
CPLMutexHolderD( phMutex );
memcpy(pImage,
poGDS->pabyRGBData + (nBand - 1) * nBlockXSize * nBlockYSize,
nBlockXSize * nBlockYSize);
Expand All @@ -305,6 +312,7 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
if (eps_decode_truecolor_block (pTempData[0], pTempData[1], pTempData[2],
poGDS->pabyBlockData, &hdr) != EPS_OK)
{
CPLMutexHolderD( phMutex );
for(iBand=0;iBand<poGDS->nBands;iBand++)
CPLFree(pTempData[iBand]);
memset(pImage, 0, nBlockXSize * nBlockYSize);
Expand All @@ -315,10 +323,12 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
CPLFree(pTempData[iBand]);

poGDS->nBufferedBlock = nBlock;
memcpy(pImage,
poGDS->pabyRGBData + (nBand - 1) * nBlockXSize * nBlockYSize,
nBlockXSize * nBlockYSize);

{
CPLMutexHolderD( phMutex );
memcpy(pImage,
poGDS->pabyRGBData + (nBand - 1) * nBlockXSize * nBlockYSize,
nBlockXSize * nBlockYSize);
}
if (nBand == 1)
{
int iOtherBand;
Expand All @@ -331,17 +341,18 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
if (poBlock == NULL)
break;

GByte* pabySrcBlock = (GByte *) poBlock->GetDataRef();
GByte* pabySrcBlock = (GByte *) poBlock->GetDataRef(TRUE);
if( pabySrcBlock == NULL )
{
poBlock->DropLock();
break;
}

memcpy(pabySrcBlock,
poGDS->pabyRGBData + (iOtherBand - 1) * nBlockXSize * nBlockYSize,
nBlockXSize * nBlockYSize);

{
CPLMutexHolderD( poBlock->GetRWMutex() );
memcpy(pabySrcBlock,
poGDS->pabyRGBData + (iOtherBand - 1) * nBlockXSize * nBlockYSize,
nBlockXSize * nBlockYSize);
}
poBlock->DropLock();
}
}
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/fit/fitdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gstEndian.h"
#include "gdal_pam.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -101,7 +102,7 @@ class FITRasterBand : public GDALPamRasterBand

// should override RasterIO eventually.

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
// virtual CPLErr WriteBlock( int, int, void * );
virtual double GetMinimum( int *pbSuccess );
virtual double GetMaximum( int *pbSuccess );
Expand Down Expand Up @@ -192,9 +193,10 @@ FITRasterBand::~FITRasterBand()
}

CPLErr FITRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
FITDataset *poFIT_DS = (FITDataset *) poDS;

uint64 tilenum = 0;
Expand Down
11 changes: 7 additions & 4 deletions gdal/frmts/fits/fitsdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "gdal_pam.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include <string.h>

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -91,8 +92,8 @@ class FITSRasterBand : public GDALPamRasterBand {
FITSRasterBand(FITSDataset*, int);
~FITSRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );
};


Expand Down Expand Up @@ -122,8 +123,9 @@ FITSRasterBand::~FITSRasterBand() {
/************************************************************************/

CPLErr FITSRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff,
void* pImage ) {
void* pImage, void ** phMutex ) {

CPLMutexHolderD( phMutex );
// A FITS block is one row (we assume BSQ formatted data)
FITSDataset* dataset = (FITSDataset*) poDS;
fitsfile* hFITS = dataset->hFITS;
Expand Down Expand Up @@ -167,8 +169,9 @@ CPLErr FITSRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr FITSRasterBand::IWriteBlock(int nBlockXOff, int nBlockYOff,
void* pImage) {
void* pImage, void ** phMutex) {

CPLMutexHolderD( phMutex );
FITSDataset* dataset = (FITSDataset*) poDS;
fitsfile* hFITS = dataset->hFITS;
int status = 0;
Expand Down
8 changes: 5 additions & 3 deletions gdal/frmts/georaster/georaster_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,8 @@ CPLErr GeoRasterDataset::IRasterIO( GDALRWFlag eRWFlag,
void *pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nBandCount, int *panBandMap,
int nPixelSpace, int nLineSpace, int nBandSpace )
int nPixelSpace, int nLineSpace, int nBandSpace,
void ** phMutex )

{
if( poGeoRaster->nBandBlockSize > 1 )
Expand All @@ -1192,15 +1193,16 @@ CPLErr GeoRasterDataset::IRasterIO( GDALRWFlag eRWFlag,
nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nBandCount, panBandMap, nPixelSpace,
nLineSpace, nBandSpace );
nLineSpace, nBandSpace, phMutex );
}
else
{
return GDALDataset::IRasterIO( eRWFlag,
nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace );
nPixelSpace, nLineSpace, nBandSpace,
phMutex );
}
}

Expand Down
7 changes: 4 additions & 3 deletions gdal/frmts/georaster/georaster_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ class GeoRasterDataset : public GDALDataset
void *pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nBandCount, int *panBandMap,
int nPixelSpace, int nLineSpace, int nBandSpace );
int nPixelSpace, int nLineSpace, int nBandSpace,
void ** phMutex = NULL );
virtual int GetGCPCount() { return nGCPCount; }
virtual const char* GetGCPProjection();
virtual const GDAL_GCP*
Expand Down Expand Up @@ -248,9 +249,9 @@ class GeoRasterRasterBand : public GDALRasterBand
virtual GDALColorInterp
GetColorInterpretation();
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff,
void *pImage );
void *pImage, void ** phMutex = NULL );
virtual CPLErr IWriteBlock( int nBlockXOff, int nBlockYOff,
void *pImage );
void *pImage, void ** phMutex = NULL );
virtual CPLErr SetStatistics( double dfMin, double dfMax,
double dfMean, double dfStdDev );
virtual CPLErr GetStatistics( int bApproxOK, int bForce,
Expand Down
9 changes: 7 additions & 2 deletions gdal/frmts/georaster/georaster_rasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "georaster_priv.h"
#include "cpl_vsi.h"
#include "cpl_error.h"
#include "cpl_multiproc.h"

// ---------------------------------------------------------------------------
// GeoRasterRasterBand()
Expand Down Expand Up @@ -204,8 +205,10 @@ GeoRasterRasterBand::~GeoRasterRasterBand()

CPLErr GeoRasterRasterBand::IReadBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void **phMutex )
{
CPLMutexHolderD( phMutex );
if( poGeoRaster->GetDataBlock( nBand,
nOverviewLevel,
nBlockXOff,
Expand Down Expand Up @@ -235,8 +238,10 @@ CPLErr GeoRasterRasterBand::IReadBlock( int nBlockXOff,

CPLErr GeoRasterRasterBand::IWriteBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void **phMutex )
{
CPLMutexHolderD( phMutex );
if( poGeoRaster->SetDataBlock( nBand,
nOverviewLevel,
nBlockXOff,
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/gff/gff_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "cpl_conv.h"
#include "cpl_vsi.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -97,7 +98,7 @@ class GFFRasterBand : public GDALPamRasterBand {
int nSampleSize;
public:
GFFRasterBand( GFFDataset *, int, GDALDataType );
virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL );
};

/************************************************************************/
Expand Down Expand Up @@ -138,8 +139,9 @@ GFFRasterBand::GFFRasterBand( GFFDataset *poDS, int nBand,
/************************************************************************/

CPLErr GFFRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void *pImage )
void *pImage, void **phMutex )
{
CPLMutexHolderD( phMutex );
GFFDataset *poGDS = (GFFDataset *)poDS;
long nOffset = poGDS->nLength;

Expand Down
9 changes: 5 additions & 4 deletions gdal/frmts/gif/biggifdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "gdal_pam.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "gifabstractdataset.h"

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -92,7 +93,7 @@ class BIGGifRasterBand : public GDALPamRasterBand
BIGGifRasterBand( BIGGIFDataset *, int );
virtual ~BIGGifRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );

virtual GDALColorInterp GetColorInterpretation();
virtual GDALColorTable *GetColorTable();
Expand Down Expand Up @@ -191,7 +192,7 @@ BIGGifRasterBand::~BIGGifRasterBand()
/************************************************************************/

CPLErr BIGGifRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
BIGGIFDataset *poGDS = (BIGGIFDataset *) poDS;
Expand All @@ -209,7 +210,7 @@ CPLErr BIGGifRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
return poGDS->poWorkDS->
RasterIO( GF_Read, 0, nBlockYOff, nBlockXSize, 1,
pImage, nBlockXSize, 1, GDT_Byte,
1, NULL, 0, 0, 0 );
1, NULL, 0, 0, 0, phMutex );
}

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -241,7 +242,7 @@ CPLErr BIGGifRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
poGDS->poWorkDS->RasterIO( GF_Write,
0, poGDS->nLastLineRead, nBlockXSize, 1,
pImage, nBlockXSize, 1, GDT_Byte,
1, NULL, 0, 0, 0 );
1, NULL, 0, 0, 0, phMutex );
}
}

Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/gif/gifdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "gdal_pam.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "gifabstractdataset.h"

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -104,7 +105,7 @@ class GIFRasterBand : public GDALPamRasterBand
GIFRasterBand( GIFDataset *, int, SavedImage *, int );
virtual ~GIFRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );

virtual double GetNoDataValue( int *pbSuccess = NULL );
virtual GDALColorInterp GetColorInterpretation();
Expand Down Expand Up @@ -235,9 +236,10 @@ GIFRasterBand::~GIFRasterBand()
/************************************************************************/

CPLErr GIFRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
CPLAssert( nBlockXOff == 0 );

if (psImage == NULL)
Expand Down
11 changes: 7 additions & 4 deletions gdal/frmts/grass/grass57dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern "C" {
#include <grass/version.h>
#include <grass/gprojects.h>
#include <grass/gis.h>
#include "cpl_multiproc.h"

#if GRASS_VERSION_MAJOR >= 7
char *GPJ_grass_to_wkt(const struct Key_Value *,
Expand Down Expand Up @@ -180,8 +181,8 @@ class GRASSRasterBand : public GDALRasterBand
const char *, const char * );
virtual ~GRASSRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IRasterIO ( GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, int, int );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual CPLErr IRasterIO ( GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, int, int, void ** phMutex = NULL );
virtual GDALColorInterp GetColorInterpretation();
virtual GDALColorTable *GetColorTable();
virtual double GetMinimum( int *pbSuccess = NULL );
Expand Down Expand Up @@ -479,9 +480,10 @@ CPLErr GRASSRasterBand::ResetReading ( struct Cell_head *sNewWindow )
/* */
/************************************************************************/

CPLErr GRASSRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage )
CPLErr GRASSRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
if ( ! this->valid ) return CE_Failure;

// Reset window because IRasterIO could be previosly called
Expand Down Expand Up @@ -527,8 +529,9 @@ CPLErr GRASSRasterBand::IRasterIO ( GDALRWFlag eRWFlag,
int nXOff, int nYOff, int nXSize, int nYSize,
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nPixelSpace, int nLineSpace )
int nPixelSpace, int nLineSpace, void ** phMutex )
{
CPLMutexHolderD( phMutex );
/* GRASS library does that, we have only calculate and reset the region in map units
* and if the region has changed, reopen the raster */

Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/grass/grassdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "gdal_priv.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "ogr_spatialref.h"

CPL_CVSID("$Id$");
Expand Down Expand Up @@ -108,7 +109,7 @@ class GRASSRasterBand : public GDALRasterBand
const char *, const char * );
virtual ~GRASSRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual GDALColorInterp GetColorInterpretation();
virtual GDALColorTable *GetColorTable();
virtual double GetMinimum( int *pbSuccess = NULL );
Expand Down Expand Up @@ -259,9 +260,10 @@ GRASSRasterBand::~GRASSRasterBand()
/************************************************************************/

CPLErr GRASSRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
char *pachNullBuf;

pachNullBuf = (char *) CPLMalloc(nBlockXSize);
Expand Down
5 changes: 3 additions & 2 deletions gdal/frmts/grib/gribdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class GRIBRasterBand : public GDALPamRasterBand
public:
GRIBRasterBand( GRIBDataset*, int, inventoryType* );
virtual ~GRIBRasterBand();
virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex );
virtual const char *GetDescription() const;

virtual double GetNoDataValue( int *pbSuccess = NULL );
Expand Down Expand Up @@ -340,13 +340,14 @@ CPLErr GRIBRasterBand::LoadData()
/************************************************************************/

CPLErr GRIBRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLErr eErr = LoadData();
if (eErr != CE_None)
return eErr;

CPLMutexHolderD( phMutex );
/* -------------------------------------------------------------------- */
/* The image as read is always upside down to our normal */
/* orientation so we need to effectively flip it at this */
Expand Down
11 changes: 7 additions & 4 deletions gdal/frmts/gsg/gs7bgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <assert.h>

#include "gdal_pam.h"
#include "cpl_multiproc.h"

#ifndef DBL_MAX
# ifdef __DBL_MAX__
Expand Down Expand Up @@ -151,8 +152,8 @@ class GS7BGRasterBand : public GDALPamRasterBand
GS7BGRasterBand( GS7BGDataset *, int );
~GS7BGRasterBand();

CPLErr IReadBlock( int, int, void * );
CPLErr IWriteBlock( int, int, void * );
CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );
double GetMinimum( int *pbSuccess = NULL );
double GetMaximum( int *pbSuccess = NULL );

Expand Down Expand Up @@ -285,9 +286,10 @@ CPLErr GS7BGRasterBand::ScanForMinMaxZ()
/************************************************************************/

CPLErr GS7BGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
if( nBlockYOff < 0 || nBlockYOff > nRasterYSize - 1 || nBlockXOff != 0 )
return CE_Failure;

Expand Down Expand Up @@ -324,9 +326,10 @@ CPLErr GS7BGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr GS7BGRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void *pImage )
void *pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
if( eAccess == GA_ReadOnly )
{
CPLError( CE_Failure, CPLE_NoWriteAccess,
Expand Down
15 changes: 9 additions & 6 deletions gdal/frmts/gsg/gsagdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
****************************************************************************/

#include "cpl_conv.h"
#include "cpl_multiproc.h"

#include <sstream>
#include <float.h>
Expand Down Expand Up @@ -134,8 +135,8 @@ class GSAGRasterBand : public GDALPamRasterBand
GSAGRasterBand( GSAGDataset *, int, vsi_l_offset );
~GSAGRasterBand();

CPLErr IReadBlock( int, int, void * );
CPLErr IWriteBlock( int, int, void * );
CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );

double GetNoDataValue( int *pbSuccess = NULL );
double GetMinimum( int *pbSuccess = NULL );
Expand Down Expand Up @@ -298,7 +299,7 @@ CPLErr GSAGRasterBand::ScanForMinMaxZ()
/************************************************************************/

CPLErr GSAGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
static size_t nMaxLineSize = 128;
double *pdfImage = (double *)pImage;
Expand All @@ -314,11 +315,12 @@ CPLErr GSAGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
// Discover the last read block
for ( int iFoundLine = nLastReadLine - 1; iFoundLine > nBlockYOff; iFoundLine--)
{
if( IReadBlock( nBlockXOff, iFoundLine, NULL) != CE_None )
if( IReadBlock( nBlockXOff, iFoundLine, NULL, phMutex) != CE_None )
return CE_Failure;
}
}

CPLMutexHolderD( phMutex );
if( panLineOffset[nBlockYOff] == 0 )
return CE_Failure;
if( VSIFSeekL( poGDS->fp, panLineOffset[nBlockYOff], SEEK_SET ) != 0 )
Expand Down Expand Up @@ -551,9 +553,10 @@ CPLErr GSAGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr GSAGRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
if( eAccess == GA_ReadOnly )
{
CPLError( CE_Failure, CPLE_NoWriteAccess,
Expand Down Expand Up @@ -594,7 +597,7 @@ CPLErr GSAGRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
}

if( panLineOffset[nBlockYOff+1] == 0 )
IReadBlock( nBlockXOff, nBlockYOff, NULL );
IReadBlock( nBlockXOff, nBlockYOff, NULL );

if( panLineOffset[nBlockYOff+1] == 0 || panLineOffset[nBlockYOff] == 0 )
return CE_Failure;
Expand Down
11 changes: 7 additions & 4 deletions gdal/frmts/gsg/gsbgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
****************************************************************************/

#include "cpl_conv.h"
#include "cpl_multiproc.h"

#include <float.h>
#include <limits.h>
Expand Down Expand Up @@ -143,8 +144,8 @@ class GSBGRasterBand : public GDALPamRasterBand
GSBGRasterBand( GSBGDataset *, int );
~GSBGRasterBand();

CPLErr IReadBlock( int, int, void * );
CPLErr IWriteBlock( int, int, void * );
CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );

double GetNoDataValue( int *pbSuccess = NULL );
double GetMinimum( int *pbSuccess = NULL );
Expand Down Expand Up @@ -277,9 +278,10 @@ CPLErr GSBGRasterBand::ScanForMinMaxZ()
/************************************************************************/

CPLErr GSBGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
if( nBlockYOff < 0 || nBlockYOff > nRasterYSize - 1 || nBlockXOff != 0 )
return CE_Failure;

Expand Down Expand Up @@ -315,9 +317,10 @@ CPLErr GSBGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr GSBGRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void *pImage )
void *pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
if( eAccess == GA_ReadOnly )
{
CPLError( CE_Failure, CPLE_NoWriteAccess,
Expand Down
11 changes: 7 additions & 4 deletions gdal/frmts/gta/gtadataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@

#include <limits.h>
#include "cpl_port.h" // for snprintf for MSVC
#include "cpl_multiproc.h"
#include <gta/gta.hpp>
#include "gdal_pam.h"

Expand Down Expand Up @@ -284,8 +285,8 @@ class GTARasterBand : public GDALPamRasterBand
GTARasterBand( GTADataset *, int );
~GTARasterBand( );

CPLErr IReadBlock( int, int, void * );
CPLErr IWriteBlock( int, int, void * );
CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );

char **GetCategoryNames( );
CPLErr SetCategoryNames( char ** );
Expand Down Expand Up @@ -683,9 +684,10 @@ CPLErr GTARasterBand::SetColorInterpretation( GDALColorInterp )
/************************************************************************/

CPLErr GTARasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
GTADataset *poGDS = (GTADataset *) poDS;

// Read and cache block containing all bands at once
Expand Down Expand Up @@ -719,9 +721,10 @@ CPLErr GTARasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr GTARasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
GTADataset *poGDS = (GTADataset *) poDS;

if( poGDS->oHeader.compression() != gta::none )
Expand Down
325 changes: 188 additions & 137 deletions gdal/frmts/gtiff/geotiff.cpp

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions gdal/frmts/gxf/gxfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "gxfopen.h"
#include "gdal_pam.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -84,7 +85,7 @@ class GXFRasterBand : public GDALPamRasterBand
GXFRasterBand( GXFDataset *, int );
double GetNoDataValue(int* bGotNoDataValue);

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
};


Expand Down Expand Up @@ -125,9 +126,10 @@ double GXFRasterBand::GetNoDataValue(int* bGotNoDataValue)
/************************************************************************/

CPLErr GXFRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
GXFDataset *poGXF_DS = (GXFDataset *) poDS;
double *padfBuffer;
float *pafBuffer = (float *) pImage;
Expand Down
10 changes: 6 additions & 4 deletions gdal/frmts/hdf4/hdf4imagedataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ class HDF4ImageRasterBand : public GDALPamRasterBand

HDF4ImageRasterBand( HDF4ImageDataset *, int, GDALDataType );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );
virtual GDALColorInterp GetColorInterpretation();
virtual GDALColorTable *GetColorTable();
virtual double GetNoDataValue( int * );
Expand Down Expand Up @@ -259,12 +259,13 @@ HDF4ImageRasterBand::HDF4ImageRasterBand( HDF4ImageDataset *poDS, int nBand,
/************************************************************************/

CPLErr HDF4ImageRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
HDF4ImageDataset *poGDS = (HDF4ImageDataset *) poDS;
int32 aiStart[H4_MAX_NC_DIMS], aiEdges[H4_MAX_NC_DIMS];
CPLErr eErr = CE_None;

CPLMutexHolderD2( phMutex );
CPLMutexHolderD(&hHDF4Mutex);

if( poGDS->eAccess == GA_Update )
Expand Down Expand Up @@ -530,11 +531,12 @@ CPLErr HDF4ImageRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr HDF4ImageRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
HDF4ImageDataset *poGDS = (HDF4ImageDataset *)poDS;
int32 aiStart[H4_MAX_NC_DIMS], aiEdges[H4_MAX_NC_DIMS];
CPLErr eErr = CE_None;
CPLMutexHolderD2( phMutex );

CPLMutexHolderD(&hHDF4Mutex);

Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/hdf5/bagdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "gdal_pam.h"
#include "gdal_priv.h"
#include "cpl_multiproc.h"
#include "ogr_spatialref.h"
#include "cpl_string.h"

Expand Down Expand Up @@ -103,7 +104,7 @@ class BAGRasterBand : public GDALPamRasterBand

bool Initialize( hid_t hDataset, const char *pszName );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual double GetNoDataValue( int * );

virtual double GetMinimum( int *pbSuccess = NULL );
Expand Down Expand Up @@ -302,8 +303,9 @@ double BAGRasterBand::GetNoDataValue( int * pbSuccess )
/* IReadBlock() */
/************************************************************************/
CPLErr BAGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
CPLMutexHolderD( phMutex );
herr_t status;
hsize_t count[3];
H5OFFSET_TYPE offset[3];
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/hdf5/hdf5imagedataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "gdal_pam.h"
#include "gdal_priv.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "hdf5dataset.h"
#include "ogr_spatialref.h"

Expand Down Expand Up @@ -245,7 +246,7 @@ class HDF5ImageRasterBand : public GDALPamRasterBand
HDF5ImageRasterBand( HDF5ImageDataset *, int, GDALDataType );
~HDF5ImageRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual double GetNoDataValue( int * );
virtual CPLErr SetNoDataValue( double );
/* virtual CPLErr IWriteBlock( int, int, void * ); */
Expand Down Expand Up @@ -348,8 +349,9 @@ CPLErr HDF5ImageRasterBand::SetNoDataValue( double dfNoData )
/* IReadBlock() */
/************************************************************************/
CPLErr HDF5ImageRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
CPLMutexHolderD( phMutex );
herr_t status;
hsize_t count[3];
H5OFFSET_TYPE offset[3];
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/hf2/hf2dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
****************************************************************************/

#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "gdal_pam.h"
#include "ogr_spatialref.h"

Expand Down Expand Up @@ -90,7 +91,7 @@ class HF2RasterBand : public GDALPamRasterBand
HF2RasterBand( HF2Dataset *, int, GDALDataType );
~HF2RasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL );
};


Expand Down Expand Up @@ -127,9 +128,10 @@ HF2RasterBand::~HF2RasterBand()
/************************************************************************/

CPLErr HF2RasterBand::IReadBlock( int nBlockXOff, int nLineYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
HF2Dataset *poGDS = (HF2Dataset *) poDS;

int nXBlocks = (nRasterXSize + nBlockXSize - 1) / nBlockXSize;
Expand Down
20 changes: 12 additions & 8 deletions gdal/frmts/hfa/hfadataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "gdal_rat.h"
#include "hfa_p.h"
#include "ogr_spatialref.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -287,7 +288,7 @@ class CPL_DLL HFADataset : public GDALPamDataset
protected:
virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
void *, int, int, GDALDataType,
int, int *, int, int, int );
int, int *, int, int, int, void ** phMutex = NULL);

public:
HFADataset();
Expand Down Expand Up @@ -368,8 +369,8 @@ class HFARasterBand : public GDALPamRasterBand
HFARasterBand( HFADataset *, int, int );
virtual ~HFARasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL );
virtual CPLErr IWriteBlock( int, int, void *, void **phMutex = NULL );

virtual const char *GetDescription() const;
virtual void SetDescription( const char * );
Expand Down Expand Up @@ -2504,9 +2505,10 @@ GDALRasterBand *HFARasterBand::GetOverview( int i )
/************************************************************************/

CPLErr HFARasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
CPLErr eErr;

if( nThisOverview == -1 )
Expand Down Expand Up @@ -2566,9 +2568,10 @@ CPLErr HFARasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
/************************************************************************/

CPLErr HFARasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
GByte *pabyOutBuf = (GByte *) pImage;

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -5382,21 +5385,22 @@ CPLErr HFADataset::IRasterIO( GDALRWFlag eRWFlag,
void *pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nBandCount, int *panBandMap,
int nPixelSpace, int nLineSpace, int nBandSpace )
int nPixelSpace, int nLineSpace, int nBandSpace,
void ** phMutex )

{
if( hHFA->papoBand[panBandMap[0]-1]->fpExternal != NULL
&& nBandCount > 1 )
return GDALDataset::BlockBasedRasterIO(
eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nBandCount, panBandMap, nPixelSpace, nLineSpace, nBandSpace );
nBandCount, panBandMap, nPixelSpace, nLineSpace, nBandSpace, phMutex );
else
return
GDALDataset::IRasterIO( eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace );
nPixelSpace, nLineSpace, nBandSpace, phMutex );
}

/************************************************************************/
Expand Down
13 changes: 9 additions & 4 deletions gdal/frmts/idrisi/IdrisiDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "cpl_conv.h"
#include "cpl_string.h"
#include "cpl_csv.h"
#include "cpl_multiproc.h"
#include "ogr_spatialref.h"
#include "gdal_pam.h"
#include "gdal_alg.h"
Expand Down Expand Up @@ -503,8 +504,8 @@ class IdrisiRasterBand : public GDALPamRasterBand
virtual double GetNoDataValue( int *pbSuccess = NULL );
virtual double GetMinimum( int *pbSuccess = NULL );
virtual double GetMaximum( int *pbSuccess = NULL );
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage );
virtual CPLErr IWriteBlock( int nBlockXOff, int nBlockYOff, void *pImage );
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage, void ** phMutex = NULL );
virtual CPLErr IWriteBlock( int nBlockXOff, int nBlockYOff, void *pImage, void ** phMutex = NULL );
virtual GDALColorTable *GetColorTable();
virtual GDALColorInterp GetColorInterpretation();
virtual char **GetCategoryNames();
Expand Down Expand Up @@ -1514,8 +1515,10 @@ IdrisiRasterBand::~IdrisiRasterBand()

CPLErr IdrisiRasterBand::IReadBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void ** phMutex )
{
CPLMutexHolderD( phMutex );
IdrisiDataset *poGDS = (IdrisiDataset *) poDS;

if( VSIFSeekL( poGDS->fp,
Expand Down Expand Up @@ -1562,8 +1565,10 @@ CPLErr IdrisiRasterBand::IReadBlock( int nBlockXOff,

CPLErr IdrisiRasterBand::IWriteBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void **phMutex )
{
CPLMutexHolderD( phMutex );
IdrisiDataset *poGDS = (IdrisiDataset *) poDS;

#ifdef CPL_MSB
Expand Down
7 changes: 5 additions & 2 deletions gdal/frmts/ilwis/ilwisdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


#include "ilwisdataset.h"
#include "cpl_multiproc.h"
#include <float.h>
#include <limits.h>

Expand Down Expand Up @@ -1462,8 +1463,9 @@ CPLErr ILWISRasterBand::GetILWISInfo(string pszFileName)
/* IReadBlock() */
/************************************************************************/
CPLErr ILWISRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
CPLMutexHolderD( phMutex );
// pImage is empty; this function fills it with data from fpRaw
// (ILWIS data to foreign data)

Expand Down Expand Up @@ -1654,8 +1656,9 @@ void ILWISRasterBand::FillWithNoData(void * pImage)
/************************************************************************/

CPLErr ILWISRasterBand::IWriteBlock(int nBlockXOff, int nBlockYOff,
void* pImage)
void* pImage, void ** phMutex)
{
CPLMutexHolderD( phMutex );
// pImage has data; this function reads this data and stores it to fpRaw
// (foreign data to ILWIS data)

Expand Down
4 changes: 2 additions & 2 deletions gdal/frmts/ilwis/ilwisdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class ILWISRasterBand : public GDALPamRasterBand
CPLErr GetILWISInfo(std::string pszFileName);
void ILWISOpen( std::string pszFilename);

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IWriteBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual CPLErr IWriteBlock( int, int, void *, void ** phMutex = NULL );
virtual double GetNoDataValue( int *pbSuccess );

private:
Expand Down
24 changes: 18 additions & 6 deletions gdal/frmts/ingr/IntergraphBand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "cpl_conv.h"
#include "cpl_string.h"
#include "cpl_csv.h"
#include "cpl_multiproc.h"
#include "ogr_spatialref.h"
#include "gdal_pam.h"
#include "gdal_alg.h"
Expand Down Expand Up @@ -360,8 +361,10 @@ CPLErr IntergraphRasterBand::SetStatistics( double dfMin,

CPLErr IntergraphRasterBand::IReadBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void **phMutex )
{
CPLMutexHolderD( phMutex );
// --------------------------------------------------------------------
// Load Block Buffer
// --------------------------------------------------------------------
Expand Down Expand Up @@ -474,14 +477,17 @@ IntergraphRGBBand::IntergraphRGBBand( IntergraphDataset *poDS,

CPLErr IntergraphRGBBand::IReadBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void **phMutex )
{
if( IntergraphRasterBand::IReadBlock( nBlockXOff,
nBlockYOff,
pImage ) != CE_None )
pImage,
phMutex ) != CE_None )
{
return CE_Failure;
}
CPLMutexHolderD( phMutex );

// --------------------------------------------------------------------
// Extract the band of interest from the block buffer
Expand Down Expand Up @@ -612,8 +618,10 @@ IntergraphRLEBand::~IntergraphRLEBand()

CPLErr IntergraphRLEBand::IReadBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void **phMutex )
{
CPLMutexHolderD( phMutex );
// --------------------------------------------------------------------
// Load Block Buffer
// --------------------------------------------------------------------
Expand Down Expand Up @@ -882,8 +890,10 @@ GDALColorInterp IntergraphBitmapBand::GetColorInterpretation()

CPLErr IntergraphBitmapBand::IReadBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void **phMutex )
{
CPLMutexHolderD( phMutex );
IntergraphDataset *poGDS = ( IntergraphDataset * ) poDS;

// ----------------------------------------------------------------
Expand Down Expand Up @@ -1080,8 +1090,10 @@ void IntergraphRasterBand::ReshapeBlock( int nBlockXOff,

CPLErr IntergraphRasterBand::IWriteBlock( int nBlockXOff,
int nBlockYOff,
void *pImage )
void *pImage,
void **phMutex )
{
CPLMutexHolderD( phMutex );
uint32 nBlockSize = nBlockBufSize;
uint32 nBlockOffset = nBlockBufSize * nBlockYOff;

Expand Down
10 changes: 5 additions & 5 deletions gdal/frmts/ingr/IntergraphBand.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class IntergraphRasterBand : public GDALPamRasterBand
virtual double GetMaximum( int *pbSuccess = NULL );
virtual GDALColorTable *GetColorTable();
virtual GDALColorInterp GetColorInterpretation();
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage );
virtual CPLErr IWriteBlock( int nBlockXOff, int nBlockYOff, void *pImage );
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage, void **phMutex = NULL );
virtual CPLErr IWriteBlock( int nBlockXOff, int nBlockYOff, void *pImage, void **phMutex = NULL );
virtual CPLErr SetColorTable( GDALColorTable *poColorTable );
virtual CPLErr SetStatistics( double dfMin, double dfMax, double dfMean, double dfStdDev );

Expand All @@ -97,7 +97,7 @@ class IntergraphRGBBand : public IntergraphRasterBand
int nBandOffset,
int nRGorB );

virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage );
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage, void **phMutex = NULL );
};

// ----------------------------------------------------------------------------
Expand All @@ -121,7 +121,7 @@ class IntergraphBitmapBand : public IntergraphRasterBand
int nRGorB = 1 );
~IntergraphBitmapBand();

virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage );
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage, void **phMutex = NULL );
virtual GDALColorInterp GetColorInterpretation();
};

Expand All @@ -146,5 +146,5 @@ class IntergraphRLEBand : public IntergraphRasterBand
int nRGorB = 0);
~IntergraphRLEBand();

virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage );
virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage, void **phMutex = NULL );
};
6 changes: 4 additions & 2 deletions gdal/frmts/iris/irisdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "gdal_pam.h"
#include "ogr_spatialref.h"
#include "cpl_multiproc.h"
#include <sstream>


Expand Down Expand Up @@ -158,7 +159,7 @@ class IRISRasterBand : public GDALPamRasterBand
IRISRasterBand( IRISDataset *, int );
~IRISRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );

virtual double GetNoDataValue( int * );
virtual CPLErr SetNoDataValue( double );
Expand Down Expand Up @@ -190,9 +191,10 @@ IRISRasterBand::~IRISRasterBand()
/************************************************************************/

CPLErr IRISRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
IRISDataset *poGDS = (IRISDataset *) poDS;

//Every product type has it's own size. TODO: Move it like dataType
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/jaxapalsar/jaxapalsardataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
****************************************************************************/

#include "gdal_pam.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -210,7 +211,7 @@ class PALSARJaxaRasterBand : public GDALRasterBand {
PALSARJaxaRasterBand( PALSARJaxaDataset *poDS, int nBand, VSILFILE *fp );
~PALSARJaxaRasterBand();

CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage );
CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage, void ** phMutex = NULL);
};

/************************************************************************/
Expand Down Expand Up @@ -299,8 +300,9 @@ PALSARJaxaRasterBand::~PALSARJaxaRasterBand()
/************************************************************************/

CPLErr PALSARJaxaRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void *pImage )
void *pImage, void ** phMutex )
{
CPLMutexHolderD( phMutex );
int nNumBytes = 0;
if (nFileType == level_11) {
nNumBytes = 8;
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/jdem/jdemdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
****************************************************************************/

#include "gdal_pam.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -119,7 +120,7 @@ class JDEMRasterBand : public GDALPamRasterBand
JDEMRasterBand( JDEMDataset *, int );
~JDEMRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
};


Expand Down Expand Up @@ -158,9 +159,10 @@ JDEMRasterBand::~JDEMRasterBand()
/************************************************************************/

CPLErr JDEMRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )

{
CPLMutexHolderD( phMutex );
JDEMDataset *poGDS = (JDEMDataset *) poDS;
int i;

Expand Down
27 changes: 18 additions & 9 deletions gdal/frmts/jp2kak/jp2kakdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class JP2KAKRasterBand : public GDALPamRasterBand

virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
void *, int, int, GDALDataType,
int, int );
int, int, void ** phMutex = NULL );

int HasExternalOverviews()
{ return GDALPamRasterBand::GetOverviewCount() != 0; }
Expand All @@ -183,7 +183,7 @@ class JP2KAKRasterBand : public GDALPamRasterBand
jp2_channels, JP2KAKDataset * );
~JP2KAKRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );

virtual int GetOverviewCount();
virtual GDALRasterBand *GetOverview( int );
Expand Down Expand Up @@ -489,7 +489,7 @@ GDALRasterBand *JP2KAKRasterBand::GetOverview( int iOverviewIndex )
/************************************************************************/

CPLErr JP2KAKRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
int nWordSize = GDALGetDataTypeSize( eDataType ) / 8;
int nOvMult = 1, nLevelsLeft = nDiscardLevels;
Expand Down Expand Up @@ -532,19 +532,23 @@ CPLErr JP2KAKRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
}

if( nXSize != nBlockXSize || nYSize != nBlockYSize )
{
CPLMutexHolderD( phMutex );
memset( pImage, 0, nBlockXSize * nBlockYSize * nWordSize );

}
/* -------------------------------------------------------------------- */
/* By default we invoke just for the requested band, directly */
/* into the target buffer. */
/* -------------------------------------------------------------------- */
if( !poBaseDS->bUseYCC )
{
CPLMutexHolderD( phMutex );
return poBaseDS->DirectRasterIO( GF_Read,
nWXOff, nWYOff, nWXSize, nWYSize,
pImage, nXSize, nYSize,
eDataType, 1, &nBand,
nWordSize, nWordSize*nBlockXSize, 0 );

}
/* -------------------------------------------------------------------- */
/* But for YCC or possible other effectively pixel interleaved */
/* products, we read all bands into a single buffer, fetch out */
Expand Down Expand Up @@ -582,6 +586,7 @@ CPLErr JP2KAKRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
if( anBands[iBand] == nBand )
{
// application requested band.
CPLMutexHolderD( phMutex );
memcpy( pImage, pabyWrkBuffer + nBandStart,
nWordSize * nBlockXSize * nBlockYSize );
}
Expand Down Expand Up @@ -618,8 +623,11 @@ CPLErr JP2KAKRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,

if( poBlock )
{
memcpy( poBlock->GetDataRef(), pabyWrkBuffer + nBandStart,
nWordSize * nBlockXSize * nBlockYSize );
{
CPLMutexHolderD( poBlock->GetRWMutex() );
memcpy( poBlock->GetDataRef( TRUE ), pabyWrkBuffer + nBandStart,
nWordSize * nBlockXSize * nBlockYSize );
}
poBlock->DropLock();
}
}
Expand All @@ -641,7 +649,7 @@ JP2KAKRasterBand::IRasterIO( GDALRWFlag eRWFlag,
int nXOff, int nYOff, int nXSize, int nYSize,
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nPixelSpace,int nLineSpace )
int nPixelSpace,int nLineSpace, void **phMutex )

{
/* -------------------------------------------------------------------- */
Expand All @@ -653,7 +661,7 @@ JP2KAKRasterBand::IRasterIO( GDALRWFlag eRWFlag,
return GDALPamRasterBand::IRasterIO(
eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nPixelSpace, nLineSpace );
nPixelSpace, nLineSpace, phMutex );
else
{
int nOverviewDiscard = nDiscardLevels;
Expand All @@ -668,6 +676,7 @@ JP2KAKRasterBand::IRasterIO( GDALRWFlag eRWFlag,
nOverviewDiscard--;
}

CPLMutexHolderD( phMutex );
return poBaseDS->DirectRasterIO(
eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
Expand Down
141 changes: 75 additions & 66 deletions gdal/frmts/jpeg/jpgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "gdal_pam.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "gdalexif.h"
#include "memdataset.h"

Expand Down Expand Up @@ -232,7 +233,7 @@ class JPGDatasetCommon : public GDALPamDataset

virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
void *, int, int, GDALDataType,
int, int *, int, int, int );
int, int *, int, int, int, void ** phMutex = NULL );

virtual CPLErr GetGeoTransform( double * );

Expand Down Expand Up @@ -311,7 +312,7 @@ class JPGRasterBand : public GDALPamRasterBand

JPGRasterBand( JPGDatasetCommon *, int );

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL);
virtual GDALColorInterp GetColorInterpretation();

virtual GDALRasterBand *GetMaskBand();
Expand All @@ -332,7 +333,7 @@ class JPGRasterBand : public GDALPamRasterBand
class JPGMaskBand : public GDALRasterBand
{
protected:
virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL );

public:
JPGMaskBand( JPGDataset *poDS );
Expand Down Expand Up @@ -785,9 +786,11 @@ JPGMaskBand::JPGMaskBand( JPGDataset *poDS )
/* IReadBlock() */
/************************************************************************/

CPLErr JPGMaskBand::IReadBlock( int nBlockX, int nBlockY, void *pImage )
CPLErr JPGMaskBand::IReadBlock( int nBlockX, int nBlockY,
void *pImage, void **phMutex )

{
CPLMutexHolderD( phMutex );
JPGDataset *poJDS = (JPGDataset *) poDS;

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -864,90 +867,93 @@ GDALRasterBand* JPGCreateBand(JPGDatasetCommon* poDS, int nBand)
/************************************************************************/

CPLErr JPGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void **phMutex )

{
CPLErr eErr;
int nXSize = GetXSize();
int nWordSize = GDALGetDataTypeSize(eDataType) / 8;

CPLAssert( nBlockXOff == 0 );

if (poGDS->fpImage == NULL)
{
memset( pImage, 0, nXSize * nWordSize );
return CE_None;
}
CPLMutexHolderD( phMutex );

/* -------------------------------------------------------------------- */
/* Load the desired scanline into the working buffer. */
/* -------------------------------------------------------------------- */
eErr = poGDS->LoadScanline( nBlockYOff );
if( eErr != CE_None )
return eErr;
if (poGDS->fpImage == NULL)
{
memset( pImage, 0, nXSize * nWordSize );
return CE_None;
}

/* -------------------------------------------------------------------- */
/* Transfer between the working buffer the the callers buffer. */
/* -------------------------------------------------------------------- */
if( poGDS->GetRasterCount() == 1 )
{
/* -------------------------------------------------------------------- */
/* Load the desired scanline into the working buffer. */
/* -------------------------------------------------------------------- */
eErr = poGDS->LoadScanline( nBlockYOff );
if( eErr != CE_None )
return eErr;

/* -------------------------------------------------------------------- */
/* Transfer between the working buffer the the callers buffer. */
/* -------------------------------------------------------------------- */
if( poGDS->GetRasterCount() == 1 )
{
#ifdef JPEG_LIB_MK1_OR_12BIT
GDALCopyWords( poGDS->pabyScanline, GDT_UInt16, 2,
pImage, eDataType, nWordSize,
nXSize );
GDALCopyWords( poGDS->pabyScanline, GDT_UInt16, 2,
pImage, eDataType, nWordSize,
nXSize );
#else
memcpy( pImage, poGDS->pabyScanline, nXSize * nWordSize );
memcpy( pImage, poGDS->pabyScanline, nXSize * nWordSize );
#endif
}
else
{
}
else
{
#ifdef JPEG_LIB_MK1_OR_12BIT
GDALCopyWords( poGDS->pabyScanline + (nBand-1) * 2,
GDT_UInt16, 6,
pImage, eDataType, nWordSize,
nXSize );
GDALCopyWords( poGDS->pabyScanline + (nBand-1) * 2,
GDT_UInt16, 6,
pImage, eDataType, nWordSize,
nXSize );
#else
if (poGDS->eGDALColorSpace == JCS_RGB &&
poGDS->GetOutColorSpace() == JCS_CMYK)
{
CPLAssert(eDataType == GDT_Byte);
int i;
if (nBand == 1)
if (poGDS->eGDALColorSpace == JCS_RGB &&
poGDS->GetOutColorSpace() == JCS_CMYK)
{
for(i=0;i<nXSize;i++)
CPLAssert(eDataType == GDT_Byte);
int i;
if (nBand == 1)
{
int C = poGDS->pabyScanline[i * 4 + 0];
int K = poGDS->pabyScanline[i * 4 + 3];
((GByte*)pImage)[i] = (GByte) ((C * K) / 255);
for(i=0;i<nXSize;i++)
{
int C = poGDS->pabyScanline[i * 4 + 0];
int K = poGDS->pabyScanline[i * 4 + 3];
((GByte*)pImage)[i] = (GByte) ((C * K) / 255);
}
}
}
else if (nBand == 2)
{
for(i=0;i<nXSize;i++)
else if (nBand == 2)
{
int M = poGDS->pabyScanline[i * 4 + 1];
int K = poGDS->pabyScanline[i * 4 + 3];
((GByte*)pImage)[i] = (GByte) ((M * K) / 255);
for(i=0;i<nXSize;i++)
{
int M = poGDS->pabyScanline[i * 4 + 1];
int K = poGDS->pabyScanline[i * 4 + 3];
((GByte*)pImage)[i] = (GByte) ((M * K) / 255);
}
}
}
else if (nBand == 3)
{
for(i=0;i<nXSize;i++)
else if (nBand == 3)
{
int Y = poGDS->pabyScanline[i * 4 + 2];
int K = poGDS->pabyScanline[i * 4 + 3];
((GByte*)pImage)[i] = (GByte) ((Y * K) / 255);
for(i=0;i<nXSize;i++)
{
int Y = poGDS->pabyScanline[i * 4 + 2];
int K = poGDS->pabyScanline[i * 4 + 3];
((GByte*)pImage)[i] = (GByte) ((Y * K) / 255);
}
}
}
}
else
{
GDALCopyWords( poGDS->pabyScanline + (nBand-1) * nWordSize,
eDataType, nWordSize * poGDS->GetRasterCount(),
pImage, eDataType, nWordSize,
nXSize );
}
else
{
GDALCopyWords( poGDS->pabyScanline + (nBand-1) * nWordSize,
eDataType, nWordSize * poGDS->GetRasterCount(),
pImage, eDataType, nWordSize,
nXSize );
}
#endif
}
}

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -1917,7 +1923,8 @@ CPLErr JPGDatasetCommon::IRasterIO( GDALRWFlag eRWFlag,
void *pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
int nBandCount, int *panBandMap,
int nPixelSpace, int nLineSpace, int nBandSpace )
int nPixelSpace, int nLineSpace, int nBandSpace,
void ** phMutex )

{
if((eRWFlag == GF_Read) &&
Expand All @@ -1934,6 +1941,7 @@ CPLErr JPGDatasetCommon::IRasterIO( GDALRWFlag eRWFlag,
(panBandMap != NULL) &&
(panBandMap[0] == 1) && (panBandMap[1] == 2) && (panBandMap[2] == 3))
{
CPLMutexHolderD( phMutex );
Restart();
int y;
CPLErr tmpError;
Expand All @@ -1960,7 +1968,8 @@ CPLErr JPGDatasetCommon::IRasterIO( GDALRWFlag eRWFlag,
return GDALPamDataset::IRasterIO(eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nBandCount, panBandMap,
nPixelSpace, nLineSpace, nBandSpace);
nPixelSpace, nLineSpace, nBandSpace,
phMutex);
}

#if JPEG_LIB_VERSION_MAJOR < 9
Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/jpeg2000/jpeg2000dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "gdaljp2abstractdataset.h"
#include "gdaljp2metadata.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"

#include <jasper/jasper.h>
#include "jpeg2000_vsil_io.h"
Expand Down Expand Up @@ -210,7 +211,7 @@ class JPEG2000RasterBand : public GDALPamRasterBand
JPEG2000RasterBand( JPEG2000Dataset *, int, int, int );
~JPEG2000RasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void **phMutex = NULL );
virtual GDALColorInterp GetColorInterpretation();
};

Expand Down Expand Up @@ -275,7 +276,7 @@ JPEG2000RasterBand::~JPEG2000RasterBand()
/************************************************************************/

CPLErr JPEG2000RasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
int i, j;

Expand All @@ -285,6 +286,7 @@ CPLErr JPEG2000RasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
return CE_Failure;
}

CPLMutexHolderD( phMutex );
// Now we can calculate the pixel offset of the top left by multiplying
// block offset with the block size.

Expand Down
6 changes: 4 additions & 2 deletions gdal/frmts/jpegls/jpeglsdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "gdal_pam.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"

/* CharLS header */
#include <interface.h>
Expand Down Expand Up @@ -85,7 +86,7 @@ class JPEGLSRasterBand : public GDALPamRasterBand
JPEGLSRasterBand( JPEGLSDataset * poDS, int nBand);
~JPEGLSRasterBand();

virtual CPLErr IReadBlock( int, int, void * );
virtual CPLErr IReadBlock( int, int, void *, void ** phMutex = NULL );
virtual GDALColorInterp GetColorInterpretation();
};

Expand Down Expand Up @@ -139,8 +140,9 @@ static const char* JPEGLSGetErrorAsString(JLS_ERROR eCode)
/************************************************************************/

CPLErr JPEGLSRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
void * pImage, void ** phMutex )
{
CPLMutexHolderD( phMutex );
JPEGLSDataset *poGDS = (JPEGLSDataset *) poDS;

if (!poGDS->bHasUncompressed)
Expand Down
Loading