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
57 typedef void (*CPLThreadFunc)(
void *);
59 void CPL_DLL *CPLLockFile(
const char *pszPath,
double dfWaitInSeconds);
60 void CPL_DLL CPLUnlockFile(
void *hLock);
63 typedef struct _CPLMutex CPLMutex;
64 typedef struct _CPLCond CPLCond;
65 typedef struct _CPLJoinableThread CPLJoinableThread;
69 #define CPLJoinableThread void
73 #define CPL_MUTEX_RECURSIVE 0
74 #define CPL_MUTEX_ADAPTIVE 1
75 #define CPL_MUTEX_REGULAR 2
77 CPLMutex CPL_DLL *CPLCreateMutex(
void);
78 CPLMutex CPL_DLL *CPLCreateMutexEx(
int nOptions);
79 int CPL_DLL CPLCreateOrAcquireMutex(CPLMutex **,
double dfWaitInSeconds);
80 int CPL_DLL CPLCreateOrAcquireMutexEx(CPLMutex **,
double dfWaitInSeconds,
82 int CPL_DLL CPLAcquireMutex(CPLMutex *hMutex,
double dfWaitInSeconds);
83 void CPL_DLL CPLReleaseMutex(CPLMutex *hMutex);
84 void CPL_DLL CPLDestroyMutex(CPLMutex *hMutex);
85 void CPL_DLL CPLCleanupMasterMutex(
void);
87 CPLCond CPL_DLL *CPLCreateCond(
void);
88 void CPL_DLL CPLCondWait(CPLCond *hCond, CPLMutex *hMutex);
92 COND_TIMED_WAIT_TIME_OUT,
94 } CPLCondTimedWaitReason;
95 CPLCondTimedWaitReason CPL_DLL CPLCondTimedWait(CPLCond *hCond,
97 double dfWaitInSeconds);
98 void CPL_DLL CPLCondSignal(CPLCond *hCond);
99 void CPL_DLL CPLCondBroadcast(CPLCond *hCond);
100 void CPL_DLL CPLDestroyCond(CPLCond *hCond);
104 GIntBig CPL_DLL CPLGetPID(
void);
105 int CPL_DLL CPLGetCurrentProcessID(
void);
106 int CPL_DLL CPLCreateThread(CPLThreadFunc pfnMain,
void *pArg);
107 CPLJoinableThread CPL_DLL *CPLCreateJoinableThread(CPLThreadFunc pfnMain,
109 void CPL_DLL CPLJoinThread(CPLJoinableThread *hJoinableThread);
110 void CPL_DLL CPLSleep(
double dfWaitInSeconds);
112 const char CPL_DLL *CPLGetThreadingModel(
void);
114 int CPL_DLL CPLGetNumCPUs(
void);
116 typedef struct _CPLLock CPLLock;
123 LOCK_RECURSIVE_MUTEX,
128 CPLLock CPL_DLL *CPLCreateLock(CPLLockType eType);
129 int CPL_DLL CPLCreateOrAcquireLock(CPLLock **, CPLLockType eType);
130 int CPL_DLL CPLAcquireLock(CPLLock *);
131 void CPL_DLL CPLReleaseLock(CPLLock *);
132 void CPL_DLL CPLDestroyLock(CPLLock *);
133 void CPL_DLL CPLLockSetDebugPerf(
139 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
143 #define CPLMutexHolderD(x) CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__)
147 #define CPLMutexHolderExD(x, nOptions) \
148 CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__, nOptions)
152 #define CPLMutexHolderOptionalLockD(x) \
153 CPLMutexHolder oHolder(x, 1000.0, __FILE__, __LINE__)
159 CPLMutex *hMutex =
nullptr;
161 const char *pszFile =
nullptr;
168 explicit CPLMutexHolder(CPLMutex **phMutex,
double dfWaitInSeconds = 1000.0,
169 const char *pszFile = __FILE__,
170 int nLine = __LINE__,
171 int nOptions = CPL_MUTEX_RECURSIVE);
175 explicit CPLMutexHolder(CPLMutex *hMutex,
double dfWaitInSeconds = 1000.0,
176 const char *pszFile = __FILE__,
177 int nLine = __LINE__);
184 #define CPLLockHolderD(x, eType) \
185 CPLLockHolder oHolder(x, eType, __FILE__, __LINE__);
189 #define CPLLockHolderOptionalLockD(x) \
190 CPLLockHolder oHolder(x, __FILE__, __LINE__);
196 CPLLock *hLock =
nullptr;
197 const char *pszFile =
nullptr;
205 const char *pszFile = __FILE__,
int nLine = __LINE__);
209 explicit CPLLockHolder(CPLLock *hSpin,
const char *pszFile = __FILE__,
210 int nLine = __LINE__);
221 #define CTLS_RLBUFFERINFO 1
222 #define CTLS_WIN32_COND 2
223 #define CTLS_CSVTABLEPTR 3
224 #define CTLS_CSVDEFAULTFILENAME 4
225 #define CTLS_ERRORCONTEXT 5
226 #define CTLS_VSICURL_CACHEDCONNECTION 6
227 #define CTLS_PATHBUF 7
228 #define CTLS_ABSTRACTARCHIVE_SPLIT 8
229 #define CTLS_GDALOPEN_ANTIRECURSION 9
230 #define CTLS_CPLSPRINTF 10
231 #define CTLS_RESPONSIBLEPID 11
232 #define CTLS_VERSIONINFO 12
233 #define CTLS_VERSIONINFO_LICENCE 13
234 #define CTLS_CONFIGOPTIONS 14
235 #define CTLS_FINDFILE 15
236 #define CTLS_VSIERRORCONTEXT 16
238 #define CTLS_PROJCONTEXTHOLDER 18
239 #define CTLS_GDALDEFAULTOVR_ANTIREC 19
240 #define CTLS_HTTPFETCHCALLBACK 20
245 void CPL_DLL *CPLGetTLS(
int nIndex);
246 void CPL_DLL *CPLGetTLSEx(
int nIndex,
int *pbMemoryErrorOccurred);
247 void CPL_DLL CPLSetTLS(
int nIndex,
void *pData,
int bFreeOnExit);
251 typedef void (*CPLTLSFreeFunc)(
void *pData);
252 void CPL_DLL CPLSetTLSWithFreeFunc(
int nIndex,
void *pData,
253 CPLTLSFreeFunc pfnFree);
254 void CPL_DLL CPLSetTLSWithFreeFuncEx(
int nIndex,
void *pData,
255 CPLTLSFreeFunc pfnFree,
256 int *pbMemoryErrorOccurred);
258 void CPL_DLL CPLCleanupTLS(
void);