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

Generated for GDAL by doxygen 1.8.11.