GDAL
cpl_multiproc.h
1 /**********************************************************************
2  * $Id: cpl_multiproc.h 25716 2013-03-09 12:09:29Z rouault $
3  *
4  * Project: CPL - Common Portability Library
5  * Purpose: CPL Multi-Threading, and process handling portability functions.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  **********************************************************************
9  * Copyright (c) 2002, Frank Warmerdam
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef _CPL_MULTIPROC_H_INCLUDED_
31 #define _CPL_MULTIPROC_H_INCLUDED_
32 
33 #include "cpl_port.h"
34 
35 /*
36 ** There are three primary implementations of the multi-process support
37 ** controlled by one of CPL_MULTIPROC_WIN32, CPL_MULTIPROC_PTHREAD or
38 ** CPL_MULTIPROC_STUB being defined. If none are defined, the stub
39 ** implementation will be used.
40 */
41 
42 #if defined(WIN32) && !defined(CPL_MULTIPROC_STUB)
43 # define CPL_MULTIPROC_WIN32
44 /* MinGW can have pthread support, so disable it to avoid issues */
45 /* in cpl_multiproc.cpp */
46 # undef CPL_MULTIPROC_PTHREAD
47 #endif
48 
49 #if !defined(CPL_MULTIPROC_WIN32) && !defined(CPL_MULTIPROC_PTHREAD) \
50  && !defined(CPL_MULTIPROC_STUB) && !defined(CPL_MULTIPROC_NONE)
51 # define CPL_MULTIPROC_STUB
52 #endif
53 
54 CPL_C_START
55 
56 typedef void (*CPLThreadFunc)(void *);
57 
58 void CPL_DLL *CPLLockFile( const char *pszPath, double dfWaitInSeconds );
59 void CPL_DLL CPLUnlockFile( void *hLock );
60 
61 void CPL_DLL *CPLCreateMutex();
62 int CPL_DLL CPLCreateOrAcquireMutex( void **, double dfWaitInSeconds );
63 int CPL_DLL CPLAcquireMutex( void *hMutex, double dfWaitInSeconds );
64 void CPL_DLL CPLReleaseMutex( void *hMutex );
65 void CPL_DLL CPLDestroyMutex( void *hMutex );
66 void CPL_DLL CPLCleanupMasterMutex();
67 
68 void CPL_DLL *CPLCreateCond();
69 void CPL_DLL CPLCondWait( void *hCond, void* hMutex );
70 void CPL_DLL CPLCondSignal( void *hCond );
71 void CPL_DLL CPLCondBroadcast( void *hCond );
72 void CPL_DLL CPLDestroyCond( void *hCond );
73 
74 GIntBig CPL_DLL CPLGetPID();
75 int CPL_DLL CPLCreateThread( CPLThreadFunc pfnMain, void *pArg );
76 void CPL_DLL* CPLCreateJoinableThread( CPLThreadFunc pfnMain, void *pArg );
77 void CPL_DLL CPLJoinThread(void* hJoinableThread);
78 void CPL_DLL CPLSleep( double dfWaitInSeconds );
79 
80 const char CPL_DLL *CPLGetThreadingModel();
81 
82 int CPL_DLL CPLGetNumCPUs();
83 
84 CPL_C_END
85 
86 #ifdef __cplusplus
87 
88 #define CPLMutexHolderD(x) CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__);
89 
90 class CPL_DLL CPLMutexHolder
91 {
92  private:
93  void *hMutex;
94  const char *pszFile;
95  int nLine;
96 
97  public:
98 
99  CPLMutexHolder( void **phMutex, double dfWaitInSeconds = 1000.0,
100  const char *pszFile = __FILE__,
101  int nLine = __LINE__ );
102  ~CPLMutexHolder();
103 };
104 #endif /* def __cplusplus */
105 
106 /* -------------------------------------------------------------------- */
107 /* Thread local storage. */
108 /* -------------------------------------------------------------------- */
109 
110 #define CTLS_RLBUFFERINFO 1 /* cpl_conv.cpp */
111 #define CTLS_WIN32_COND 2 /* cpl_multiproc.cpp */
112 #define CTLS_CSVTABLEPTR 3 /* cpl_csv.cpp */
113 #define CTLS_CSVDEFAULTFILENAME 4 /* cpl_csv.cpp */
114 #define CTLS_ERRORCONTEXT 5 /* cpl_error.cpp */
115 #define CTLS_GDALDATASET_REC_PROTECT_MAP 6 /* gdaldataset.cpp */
116 #define CTLS_PATHBUF 7 /* cpl_path.cpp */
117 #define CTLS_UNUSED3 8
118 #define CTLS_UNUSED4 9
119 #define CTLS_CPLSPRINTF 10 /* cpl_string.h */
120 #define CTLS_RESPONSIBLEPID 11 /* gdaldataset.cpp */
121 #define CTLS_VERSIONINFO 12 /* gdal_misc.cpp */
122 #define CTLS_VERSIONINFO_LICENCE 13 /* gdal_misc.cpp */
123 #define CTLS_CONFIGOPTIONS 14 /* cpl_conv.cpp */
124 #define CTLS_FINDFILE 15 /* cpl_findfile.cpp */
125 
126 #define CTLS_MAX 32
127 
128 CPL_C_START
129 void CPL_DLL * CPLGetTLS( int nIndex );
130 void CPL_DLL CPLSetTLS( int nIndex, void *pData, int bFreeOnExit );
131 
132 /* Warning : the CPLTLSFreeFunc must not in any case directly or indirectly */
133 /* use or fetch any TLS data, or a terminating thread will hang ! */
134 typedef void (*CPLTLSFreeFunc)( void* pData );
135 void CPL_DLL CPLSetTLSWithFreeFunc( int nIndex, void *pData, CPLTLSFreeFunc pfnFree );
136 
137 void CPL_DLL CPLCleanupTLS();
138 CPL_C_END
139 
140 #endif /* _CPL_MULTIPROC_H_INCLUDED_ */

Generated for GDAL by doxygen 1.8.4.