15#ifndef CPL_MULTIPROC_H_INCLUDED_
16#define CPL_MULTIPROC_H_INCLUDED_
27#if defined(_WIN32) && !defined(CPL_MULTIPROC_STUB)
28#define CPL_MULTIPROC_WIN32
31#undef CPL_MULTIPROC_PTHREAD
34#if !defined(CPL_MULTIPROC_WIN32) && !defined(CPL_MULTIPROC_PTHREAD) && \
35 !defined(CPL_MULTIPROC_STUB) && !defined(CPL_MULTIPROC_NONE)
36#define CPL_MULTIPROC_STUB
41typedef void (*CPLThreadFunc)(
void *);
43void CPL_DLL *CPLLockFile(
const char *pszPath,
double dfWaitInSeconds);
44void CPL_DLL CPLUnlockFile(
void *hLock);
46typedef struct _CPLMutex CPLMutex;
47typedef struct _CPLCond CPLCond;
48typedef struct _CPLJoinableThread CPLJoinableThread;
51#define CPL_MUTEX_RECURSIVE 0
52#define CPL_MUTEX_ADAPTIVE 1
53#define CPL_MUTEX_REGULAR 2
55CPLMutex CPL_DLL *CPLCreateMutex(
void);
56CPLMutex CPL_DLL *CPLCreateMutexEx(
int nOptions);
57int CPL_DLL CPLCreateOrAcquireMutex(CPLMutex **,
double dfWaitInSeconds);
58int CPL_DLL CPLCreateOrAcquireMutexEx(CPLMutex **,
double dfWaitInSeconds,
60int CPL_DLL CPLAcquireMutex(CPLMutex *hMutex,
double dfWaitInSeconds);
61void CPL_DLL CPLReleaseMutex(CPLMutex *hMutex);
62void CPL_DLL CPLDestroyMutex(CPLMutex *hMutex);
63void CPL_DLL CPLCleanupMasterMutex(
void);
65CPLCond CPL_DLL *CPLCreateCond(
void);
66void CPL_DLL CPLCondWait(CPLCond *hCond, CPLMutex *hMutex);
71 COND_TIMED_WAIT_TIME_OUT,
73} CPLCondTimedWaitReason;
75CPLCondTimedWaitReason CPL_DLL CPLCondTimedWait(CPLCond *hCond,
77 double dfWaitInSeconds);
78void CPL_DLL CPLCondSignal(CPLCond *hCond);
79void CPL_DLL CPLCondBroadcast(CPLCond *hCond);
80void CPL_DLL CPLDestroyCond(CPLCond *hCond);
85int CPL_DLL CPLGetCurrentProcessID(
void);
86int CPL_DLL CPLCreateThread(CPLThreadFunc pfnMain,
void *pArg);
87CPLJoinableThread CPL_DLL *CPLCreateJoinableThread(CPLThreadFunc pfnMain,
89void CPL_DLL CPLJoinThread(CPLJoinableThread *hJoinableThread);
90void CPL_DLL CPLSleep(
double dfWaitInSeconds);
92const char CPL_DLL *CPLGetThreadingModel(
void);
94int CPL_DLL CPLGetNumCPUs(
void);
96typedef struct _CPLLock CPLLock;
103 LOCK_RECURSIVE_MUTEX,
108CPLLock CPL_DLL *CPLCreateLock(CPLLockType eType);
109int CPL_DLL CPLCreateOrAcquireLock(CPLLock **, CPLLockType eType);
110int CPL_DLL CPLAcquireLock(CPLLock *);
111void CPL_DLL CPLReleaseLock(CPLLock *);
112void CPL_DLL CPLDestroyLock(CPLLock *);
113void CPL_DLL CPLLockSetDebugPerf(
119#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
123#define CPLMutexHolderD(x) CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__)
127#define CPLMutexHolderExD(x, nOptions) \
128 CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__, nOptions)
132#define CPLMutexHolderOptionalLockD(x) \
133 CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__)
139 CPLMutex *hMutex =
nullptr;
141 const char *pszFile =
nullptr;
148 explicit CPLMutexHolder(CPLMutex **phMutex,
double dfWaitInSeconds = 1000.0,
149 const char *pszFile = __FILE__,
150 int nLine = __LINE__,
151 int nOptions = CPL_MUTEX_RECURSIVE);
155 explicit CPLMutexHolder(CPLMutex *hMutex,
double dfWaitInSeconds = 1000.0,
156 const char *pszFile = __FILE__,
157 int nLine = __LINE__);
164#define CPLLockHolderD(x, eType) \
165 CPLLockHolder oHolder(x, eType, __FILE__, __LINE__);
169#define CPLLockHolderOptionalLockD(x) \
170 CPLLockHolder oHolder(x, __FILE__, __LINE__);
176 CPLLock *hLock =
nullptr;
177 const char *pszFile =
nullptr;
185 const char *pszFile = __FILE__,
int nLine = __LINE__);
189 explicit CPLLockHolder(CPLLock *hSpin,
const char *pszFile = __FILE__,
190 int nLine = __LINE__);
201#define CTLS_RLBUFFERINFO 1
202#define CTLS_WIN32_COND 2
203#define CTLS_CSVTABLEPTR 3
204#define CTLS_CSVDEFAULTFILENAME 4
205#define CTLS_ERRORCONTEXT 5
206#define CTLS_VSICURL_CACHEDCONNECTION 6
207#define CTLS_PATHBUF 7
208#define CTLS_ABSTRACTARCHIVE_SPLIT 8
209#define CTLS_GDALOPEN_ANTIRECURSION 9
210#define CTLS_CPLSPRINTF 10
211#define CTLS_RESPONSIBLEPID 11
212#define CTLS_VERSIONINFO 12
213#define CTLS_VERSIONINFO_LICENCE 13
214#define CTLS_CONFIGOPTIONS 14
215#define CTLS_FINDFILE 15
216#define CTLS_VSIERRORCONTEXT 16
218#define CTLS_PROJCONTEXTHOLDER 18
219#define CTLS_GDALDEFAULTOVR_ANTIREC 19
220#define CTLS_HTTPFETCHCALLBACK 20
225void CPL_DLL *CPLGetTLS(
int nIndex);
226void CPL_DLL *CPLGetTLSEx(
int nIndex,
int *pbMemoryErrorOccurred);
227void CPL_DLL CPLSetTLS(
int nIndex,
void *pData,
int bFreeOnExit);
231typedef void (*CPLTLSFreeFunc)(
void *pData);
232void CPL_DLL CPLSetTLSWithFreeFunc(
int nIndex,
void *pData,
233 CPLTLSFreeFunc pfnFree);
234void CPL_DLL CPLSetTLSWithFreeFuncEx(
int nIndex,
void *pData,
235 CPLTLSFreeFunc pfnFree,
236 int *pbMemoryErrorOccurred);
238void CPL_DLL CPLCleanupTLS(
void);
Object to hold a lock.
Definition: cpl_multiproc.h:174
Object to hold a mutex.
Definition: cpl_multiproc.h:137
Core portability definitions for CPL.
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:283
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:279
#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:1030
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:199