Skip to content

Commit bd2bd14

Browse files
author
rouault
committed
Introduce a more generic lock API (recursive mutex, adaptive mutex, spinlock); Add types for CPLMutex, CPLCond and CPLJoinableThread (only enforced in -DDEBUG mode)
git-svn-id: https://svn.osgeo.org/gdal/trunk/gdal@28459 f0d54148-0727-0410-94bb-9a71ac55c965
1 parent 8d946ee commit bd2bd14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+794
-176
lines changed

alg/gdal_tps.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void *GDALCreateTPSTransformerInt( int nGCPCount, const GDAL_GCP *pasGCPList,
209209
if( nThreads > 1 )
210210
{
211211
/* Compute direct and reverse transforms in parallel */
212-
void* hThread = CPLCreateJoinableThread(GDALTPSComputeForwardInThread, psInfo);
212+
CPLJoinableThread* hThread = CPLCreateJoinableThread(GDALTPSComputeForwardInThread, psInfo);
213213
psInfo->bReverseSolved = psInfo->poReverse->solve() != 0;
214214
if( hThread != NULL )
215215
CPLJoinThread(hThread);

alg/gdalgrid.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1293,11 +1293,11 @@ struct _GDALGridJob
12931293
int (*pfnProgress)(GDALGridJob* psJob);
12941294
GDALDataType eType;
12951295

1296-
void *hThread;
1296+
CPLJoinableThread *hThread;
12971297
volatile int *pnCounter;
12981298
volatile int *pbStop;
1299-
void *hCond;
1300-
void *hCondMutex;
1299+
CPLCond *hCond;
1300+
CPLMutex *hCondMutex;
13011301

13021302
GDALProgressFunc pfnRealProgress;
13031303
void *pRealProgressArg;

alg/gdaltransformer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2956,7 +2956,7 @@ CPLXMLNode *GDALSerializeTransformer( CPL_UNUSED GDALTransformerFunc pfnFunc,
29562956
/************************************************************************/
29572957

29582958
static CPLList* psListDeserializer = NULL;
2959-
static void* hDeserializerMutex = NULL;
2959+
static CPLMutex* hDeserializerMutex = NULL;
29602960

29612961
typedef struct
29622962
{

alg/gdalwarper.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include "gdal_alg.h"
4343
#include "cpl_minixml.h"
44+
#include "cpl_multiproc.h"
4445

4546
CPL_C_START
4647

@@ -346,8 +347,8 @@ class CPL_DLL GDALWarpOperation {
346347
CPLErr CreateKernelMask( GDALWarpKernel *, int iBand,
347348
const char *pszType );
348349

349-
void *hIOMutex;
350-
void *hWarpMutex;
350+
CPLMutex *hIOMutex;
351+
CPLMutex *hWarpMutex;
351352

352353
int nChunkListCount;
353354
int nChunkListMax;

alg/gdalwarpkernel.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ typedef struct _GWKJobStruct GWKJobStruct;
133133

134134
struct _GWKJobStruct
135135
{
136-
void *hThread;
136+
CPLJoinableThread *hThread;
137137
GDALWarpKernel *poWK;
138138
int iYMin;
139139
int iYMax;
140140
volatile int *pnCounter;
141141
volatile int *pbStop;
142-
void *hCond;
143-
void *hCondMutex;
142+
CPLCond *hCond;
143+
CPLMutex *hCondMutex;
144144
int (*pfnProgress)(GWKJobStruct* psJob);
145145
void *pTransformerArg;
146146
} ;
@@ -286,7 +286,7 @@ static CPLErr GWKRun( GDALWarpKernel *poWK,
286286
return GWKGenericMonoThread(poWK, pfnFunc);
287287
}
288288

289-
void* hCond = CPLCreateCond();
289+
CPLCond* hCond = CPLCreateCond();
290290
if (hCond == NULL)
291291
{
292292
for(i=0;i<nThreads;i++)
@@ -303,7 +303,7 @@ static CPLErr GWKRun( GDALWarpKernel *poWK,
303303

304304
CPLDebug("WARP", "Using %d threads", nThreads);
305305

306-
void* hCondMutex = CPLCreateMutex(); /* and take implicitely the mutex */
306+
CPLMutex* hCondMutex = CPLCreateMutex(); /* and take implicitely the mutex */
307307

308308
volatile int bStop = FALSE;
309309
volatile int nCounter = 0;

alg/gdalwarpoperation.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -741,15 +741,15 @@ typedef struct
741741
{
742742
GDALWarpOperation *poOperation;
743743
GDALWarpChunk *pasChunkInfo;
744-
void *hThreadHandle;
744+
CPLJoinableThread *hThreadHandle;
745745
CPLErr eErr;
746746
double dfProgressBase;
747747
double dfProgressScale;
748-
void *hIOMutex;
748+
CPLMutex *hIOMutex;
749749

750-
void *hCondMutex;
750+
CPLMutex *hCondMutex;
751751
int bIOMutexTaken;
752-
void *hCond;
752+
CPLCond *hCond;
753753
} ChunkThreadData;
754754

755755

@@ -829,8 +829,8 @@ CPLErr GDALWarpOperation::ChunkAndWarpMulti(
829829
CPLReleaseMutex( hIOMutex );
830830
CPLReleaseMutex( hWarpMutex );
831831

832-
void* hCond = CPLCreateCond();
833-
void* hCondMutex = CPLCreateMutex();
832+
CPLCond* hCond = CPLCreateCond();
833+
CPLMutex* hCondMutex = CPLCreateMutex();
834834
CPLReleaseMutex(hCondMutex);
835835

836836
/* -------------------------------------------------------------------- */

apps/multireadtest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static volatile int nPendingThreads = 0;
4040
static const char *pszFilename = NULL;
4141
static int nChecksum = 0;
4242

43-
static void *pGlobalMutex = NULL;
43+
static CPLMutex *pGlobalMutex = NULL;
4444

4545
static void WorkerFunc( void * );
4646

apps/test_ogrsf.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const char* pszLogFilename = NULL;
5252

5353
typedef struct
5454
{
55-
void* hThread;
55+
CPLJoinableThread* hThread;
5656
int bRet;
5757
} ThreadContext;
5858

configure

+77
Original file line numberDiff line numberDiff line change
@@ -17822,6 +17822,83 @@ cat >>confdefs.h <<_ACEOF
1782217822
_ACEOF
1782317823

1782417824

17825+
else
17826+
17827+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17828+
$as_echo "no" >&6; }
17829+
17830+
fi
17831+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
17832+
17833+
17834+
17835+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for HAVE_PTHREAD_MUTEX_ADAPTIVE_NP" >&5
17836+
$as_echo_n "checking for HAVE_PTHREAD_MUTEX_ADAPTIVE_NP... " >&6; }
17837+
17838+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
17839+
/* end confdefs.h. */
17840+
17841+
#define _GNU_SOURCE
17842+
#include <pthread.h>
17843+
17844+
int
17845+
main ()
17846+
{
17847+
17848+
return PTHREAD_MUTEX_ADAPTIVE_NP;
17849+
17850+
;
17851+
return 0;
17852+
}
17853+
_ACEOF
17854+
if ac_fn_c_try_compile "$LINENO"; then :
17855+
17856+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
17857+
$as_echo "yes" >&6; }
17858+
17859+
cat >>confdefs.h <<_ACEOF
17860+
#define HAVE_PTHREAD_MUTEX_ADAPTIVE_NP 1
17861+
_ACEOF
17862+
17863+
17864+
else
17865+
17866+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17867+
$as_echo "no" >&6; }
17868+
17869+
fi
17870+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
17871+
17872+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_spinlock_t" >&5
17873+
$as_echo_n "checking for pthread_spinlock_t... " >&6; }
17874+
17875+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
17876+
/* end confdefs.h. */
17877+
17878+
#define _GNU_SOURCE
17879+
#include <pthread.h>
17880+
17881+
int
17882+
main ()
17883+
{
17884+
17885+
pthread_spinlock_t spin;
17886+
return 1;
17887+
17888+
;
17889+
return 0;
17890+
}
17891+
_ACEOF
17892+
if ac_fn_c_try_compile "$LINENO"; then :
17893+
17894+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
17895+
$as_echo "yes" >&6; }
17896+
17897+
cat >>confdefs.h <<_ACEOF
17898+
#define HAVE_PTHREAD_SPINLOCK 1
17899+
_ACEOF
17900+
17901+
1782517902
else
1782617903

1782717904
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5

configure.in

+37
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,43 @@ if test "$with_threads" = "yes" -o "$with_threads" = "" ; then
506506
AC_MSG_RESULT([no])
507507
])
508508

509+
510+
511+
AC_MSG_CHECKING([for HAVE_PTHREAD_MUTEX_ADAPTIVE_NP])
512+
513+
AC_TRY_COMPILE(
514+
[
515+
#define _GNU_SOURCE
516+
#include <pthread.h>
517+
], [
518+
return PTHREAD_MUTEX_ADAPTIVE_NP;
519+
],
520+
[
521+
AC_MSG_RESULT([yes])
522+
AC_DEFINE_UNQUOTED(HAVE_PTHREAD_MUTEX_ADAPTIVE_NP, 1,
523+
[Define to 1 if you have the `PTHREAD_MUTEX_ADAPTIVE_NP' constant.])
524+
], [
525+
AC_MSG_RESULT([no])
526+
])
527+
528+
AC_MSG_CHECKING([for pthread_spinlock_t])
529+
530+
AC_TRY_COMPILE(
531+
[
532+
#define _GNU_SOURCE
533+
#include <pthread.h>
534+
], [
535+
pthread_spinlock_t spin;
536+
return 1;
537+
],
538+
[
539+
AC_MSG_RESULT([yes])
540+
AC_DEFINE_UNQUOTED(HAVE_PTHREAD_SPINLOCK, 1,
541+
[Define to 1 if you have the `pthread_spinlock_t' type.])
542+
], [
543+
AC_MSG_RESULT([no])
544+
])
545+
509546
elif test "$with_threads" != "no" ; then
510547

511548
THREAD_FLAG=CPL_MULTIPROC_PTHREAD

frmts/ecw/gdal_ecw.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class ECWAsyncReader : public GDALAsyncReader
414414
{
415415
private:
416416
CNCSJP2FileView *poFileView;
417-
void *hMutex;
417+
CPLMutex *hMutex;
418418
int bUsingCustomStream;
419419

420420
int bUpdateReady;

frmts/grib/gribdataset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ CPL_C_START
4747
void GDALRegister_GRIB(void);
4848
CPL_C_END
4949

50-
static void *hGRIBMutex = NULL;
50+
static CPLMutex *hGRIBMutex = NULL;
5151

5252
/************************************************************************/
5353
/* ==================================================================== */

frmts/gtiff/geotiff.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12209,7 +12209,7 @@ static void GTiffTagExtender(TIFF *tif)
1220912209
#include <dlfcn.h>
1221012210
#endif
1221112211

12212-
static void* hGTiffOneTimeInitMutex = NULL;
12212+
static CPLMutex* hGTiffOneTimeInitMutex = NULL;
1221312213

1221412214
int GTiffOneTimeInit()
1221512215

frmts/gtiff/gt_wkt_srs.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static const char *papszDatumEquiv[] =
9393
/* LibgeotiffOneTimeInit() */
9494
/************************************************************************/
9595

96-
static void* hMutex = NULL;
96+
static CPLMutex* hMutex = NULL;
9797

9898
void LibgeotiffOneTimeInit()
9999
{

frmts/hdf4/hdf4dataset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ CPL_C_END
5050

5151
extern const char *pszGDALSignature;
5252

53-
void *hHDF4Mutex = NULL;
53+
CPLMutex *hHDF4Mutex = NULL;
5454

5555
/************************************************************************/
5656
/* ==================================================================== */

frmts/hdf4/hdf4imagedataset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CPL_C_END
5959
const char *pszGDALSignature =
6060
"Created with GDAL (http://www.remotesensing.org/gdal/)";
6161

62-
extern void *hHDF4Mutex;
62+
extern CPLMutex *hHDF4Mutex;
6363

6464
/************************************************************************/
6565
/* ==================================================================== */

frmts/jpipkak/jpipkakdataset.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class JPIPKAKDataset: public GDALPamDataset
140140
void Deinitialize();
141141
int KakaduClassId(int nClassId);
142142

143-
void *pGlobalMutex;
143+
CPLMutex *pGlobalMutex;
144144

145145
// support two communication threads to the server, a main and an overview thread
146146
volatile int bHighThreadRunning;

frmts/netcdf/gmtdataset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
CPL_CVSID("$Id$");
3737

38-
extern void *hNCMutex; /* shared with netcdf. See netcdfdataset.cpp */
38+
extern CPLMutex *hNCMutex; /* shared with netcdf. See netcdfdataset.cpp */
3939

4040
/************************************************************************/
4141
/* ==================================================================== */

frmts/netcdf/netcdfdataset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void CopyMetadata( void *poDS, int fpImage, int CDFVarID,
8383
// uncomment this for more debug ouput
8484
// #define NCDF_DEBUG 1
8585

86-
void *hNCMutex = NULL;
86+
CPLMutex *hNCMutex = NULL;
8787

8888
/************************************************************************/
8989
/* ==================================================================== */

frmts/pcidsk/vsi_pcidsk_io.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class CPLThreadMutex : public PCIDSK::Mutex
225225

226226
{
227227
private:
228-
void *hMutex;
228+
CPLMutex *hMutex;
229229

230230
public:
231231
CPLThreadMutex();

frmts/pdf/pdfdataset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static double Get(GDALPDFObject* poObj, int nIndice = -1);
8787

8888
#ifdef HAVE_POPPLER
8989

90-
static void* hGlobalParamsMutex = NULL;
90+
static CPLMutex* hGlobalParamsMutex = NULL;
9191

9292
/************************************************************************/
9393
/* ObjectAutoFree */

frmts/postgisraster/postgisraster.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class PostGISRasterTileDataset;
180180
class PostGISRasterDriver : public GDALDriver {
181181

182182
private:
183-
void* hMutex;
183+
CPLMutex* hMutex;
184184
std::map<CPLString, PGconn*> oMapConnection;
185185
public:
186186
PostGISRasterDriver();

frmts/wms/minidriver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "wmsdriver.h"
3131

3232
static volatile GDALWMSMiniDriverManager *g_mini_driver_manager = NULL;
33-
static void *g_mini_driver_manager_mutex = NULL;
33+
static CPLMutex *g_mini_driver_manager_mutex = NULL;
3434

3535
GDALWMSMiniDriver::GDALWMSMiniDriver() {
3636
m_parent_dataset = 0;

0 commit comments

Comments
 (0)