31#ifndef CPL_MULTIPROC_H_INCLUDED_
32#define CPL_MULTIPROC_H_INCLUDED_
43#if defined(_WIN32) && !defined(CPL_MULTIPROC_STUB)
44#define CPL_MULTIPROC_WIN32
47#undef CPL_MULTIPROC_PTHREAD
50#if !defined(CPL_MULTIPROC_WIN32) && !defined(CPL_MULTIPROC_PTHREAD) && \
51 !defined(CPL_MULTIPROC_STUB) && !defined(CPL_MULTIPROC_NONE)
52#define CPL_MULTIPROC_STUB
57typedef void (*CPLThreadFunc)(
void *);
59void CPL_DLL *CPLLockFile(
const char *pszPath,
double dfWaitInSeconds);
60void CPL_DLL CPLUnlockFile(
void *hLock);
62typedef struct _CPLMutex CPLMutex;
63typedef struct _CPLCond CPLCond;
64typedef struct _CPLJoinableThread CPLJoinableThread;
67#define CPL_MUTEX_RECURSIVE 0
68#define CPL_MUTEX_ADAPTIVE 1
69#define CPL_MUTEX_REGULAR 2
71CPLMutex CPL_DLL *CPLCreateMutex(
void);
72CPLMutex CPL_DLL *CPLCreateMutexEx(
int nOptions);
73int CPL_DLL CPLCreateOrAcquireMutex(CPLMutex **,
double dfWaitInSeconds);
74int CPL_DLL CPLCreateOrAcquireMutexEx(CPLMutex **,
double dfWaitInSeconds,
76int CPL_DLL CPLAcquireMutex(CPLMutex *hMutex,
double dfWaitInSeconds);
77void CPL_DLL CPLReleaseMutex(CPLMutex *hMutex);
78void CPL_DLL CPLDestroyMutex(CPLMutex *hMutex);
79void CPL_DLL CPLCleanupMasterMutex(
void);
81CPLCond CPL_DLL *CPLCreateCond(
void);
82void CPL_DLL CPLCondWait(CPLCond *hCond, CPLMutex *hMutex);
87 COND_TIMED_WAIT_TIME_OUT,
89} CPLCondTimedWaitReason;
91CPLCondTimedWaitReason CPL_DLL CPLCondTimedWait(CPLCond *hCond,
93 double dfWaitInSeconds);
94void CPL_DLL CPLCondSignal(CPLCond *hCond);
95void CPL_DLL CPLCondBroadcast(CPLCond *hCond);
96void CPL_DLL CPLDestroyCond(CPLCond *hCond);
100GIntBig CPL_DLL CPLGetPID(
void);
101int CPL_DLL CPLGetCurrentProcessID(
void);
102int CPL_DLL CPLCreateThread(CPLThreadFunc pfnMain,
void *pArg);
103CPLJoinableThread CPL_DLL *CPLCreateJoinableThread(CPLThreadFunc pfnMain,
105void CPL_DLL CPLJoinThread(CPLJoinableThread *hJoinableThread);
106void CPL_DLL CPLSleep(
double dfWaitInSeconds);
108const char CPL_DLL *CPLGetThreadingModel(
void);
110int CPL_DLL CPLGetNumCPUs(
void);
112typedef struct _CPLLock CPLLock;
119 LOCK_RECURSIVE_MUTEX,
124CPLLock CPL_DLL *CPLCreateLock(CPLLockType eType);
125int CPL_DLL CPLCreateOrAcquireLock(CPLLock **, CPLLockType eType);
126int CPL_DLL CPLAcquireLock(CPLLock *);
127void CPL_DLL CPLReleaseLock(CPLLock *);
128void CPL_DLL CPLDestroyLock(CPLLock *);
129void CPL_DLL CPLLockSetDebugPerf(
135#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
139#define CPLMutexHolderD(x) CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__)
143#define CPLMutexHolderExD(x, nOptions) \
144 CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__, nOptions)
148#define CPLMutexHolderOptionalLockD(x) \
149 CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__)
155 CPLMutex *hMutex =
nullptr;
157 const char *pszFile =
nullptr;
164 explicit CPLMutexHolder(CPLMutex **phMutex,
double dfWaitInSeconds = 1000.0,
165 const char *pszFile = __FILE__,
166 int nLine = __LINE__,
167 int nOptions = CPL_MUTEX_RECURSIVE);
171 explicit CPLMutexHolder(CPLMutex *hMutex,
double dfWaitInSeconds = 1000.0,
172 const char *pszFile = __FILE__,
173 int nLine = __LINE__);
180#define CPLLockHolderD(x, eType) \
181 CPLLockHolder oHolder(x, eType, __FILE__, __LINE__);
185#define CPLLockHolderOptionalLockD(x) \
186 CPLLockHolder oHolder(x, __FILE__, __LINE__);
192 CPLLock *hLock =
nullptr;
193 const char *pszFile =
nullptr;
201 const char *pszFile = __FILE__,
int nLine = __LINE__);
205 explicit CPLLockHolder(CPLLock *hSpin,
const char *pszFile = __FILE__,
206 int nLine = __LINE__);
217#define CTLS_RLBUFFERINFO 1
218#define CTLS_WIN32_COND 2
219#define CTLS_CSVTABLEPTR 3
220#define CTLS_CSVDEFAULTFILENAME 4
221#define CTLS_ERRORCONTEXT 5
222#define CTLS_VSICURL_CACHEDCONNECTION 6
223#define CTLS_PATHBUF 7
224#define CTLS_ABSTRACTARCHIVE_SPLIT 8
225#define CTLS_GDALOPEN_ANTIRECURSION 9
226#define CTLS_CPLSPRINTF 10
227#define CTLS_RESPONSIBLEPID 11
228#define CTLS_VERSIONINFO 12
229#define CTLS_VERSIONINFO_LICENCE 13
230#define CTLS_CONFIGOPTIONS 14
231#define CTLS_FINDFILE 15
232#define CTLS_VSIERRORCONTEXT 16
234#define CTLS_PROJCONTEXTHOLDER 18
235#define CTLS_GDALDEFAULTOVR_ANTIREC 19
236#define CTLS_HTTPFETCHCALLBACK 20
241void CPL_DLL *CPLGetTLS(
int nIndex);
242void CPL_DLL *CPLGetTLSEx(
int nIndex,
int *pbMemoryErrorOccurred);
243void CPL_DLL CPLSetTLS(
int nIndex,
void *pData,
int bFreeOnExit);
247typedef void (*CPLTLSFreeFunc)(
void *pData);
248void CPL_DLL CPLSetTLSWithFreeFunc(
int nIndex,
void *pData,
249 CPLTLSFreeFunc pfnFree);
250void CPL_DLL CPLSetTLSWithFreeFuncEx(
int nIndex,
void *pData,
251 CPLTLSFreeFunc pfnFree,
252 int *pbMemoryErrorOccurred);
254void CPL_DLL CPLCleanupTLS(
void);
Object to hold a lock.
Definition cpl_multiproc.h:190
Object to hold a mutex.
Definition cpl_multiproc.h:153
Core portability definitions for CPL.
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:299
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:295
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:1042
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:215