OGR
cpl_multiproc.h
1 /**********************************************************************
2  * $Id: cpl_multiproc.h 23729 2012-01-08 01:11:14Z 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 
67 GIntBig CPL_DLL CPLGetPID();
68 int CPL_DLL CPLCreateThread( CPLThreadFunc pfnMain, void *pArg );
69 void CPL_DLL CPLSleep( double dfWaitInSeconds );
70 
71 const char CPL_DLL *CPLGetThreadingModel();
72 
73 CPL_C_END
74 
75 #ifdef __cplusplus
76 
77 #define CPLMutexHolderD(x) CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__);
78 
79 class CPL_DLL CPLMutexHolder
80 {
81  private:
82  void *hMutex;
83  const char *pszFile;
84  int nLine;
85 
86  public:
87 
88  CPLMutexHolder( void **phMutex, double dfWaitInSeconds = 1000.0,
89  const char *pszFile = __FILE__,
90  int nLine = __LINE__ );
91  ~CPLMutexHolder();
92 };
93 #endif /* def __cplusplus */
94 
95 /* -------------------------------------------------------------------- */
96 /* Thread local storage. */
97 /* -------------------------------------------------------------------- */
98 
99 #define CTLS_RLBUFFERINFO 1 /* cpl_conv.cpp */
100 #define CTLS_DECDMSBUFFER 2 /* cpl_conv.cpp */
101 #define CTLS_CSVTABLEPTR 3 /* cpl_csv.cpp */
102 #define CTLS_CSVDEFAULTFILENAME 4 /* cpl_csv.cpp */
103 #define CTLS_ERRORCONTEXT 5 /* cpl_error.cpp */
104 #define CTLS_UNUSED1 6
105 #define CTLS_PATHBUF 7 /* cpl_path.cpp */
106 #define CTLS_SPRINTFBUF 8 /* cpl_string.cpp */
107 #define CTLS_SWQ_ERRBUF 9 /* swq.c */
108 #define CTLS_CPLSPRINTF 10 /* cpl_string.h */
109 #define CTLS_RESPONSIBLEPID 11 /* gdaldataset.cpp */
110 #define CTLS_VERSIONINFO 12 /* gdal_misc.cpp */
111 #define CTLS_VERSIONINFO_LICENCE 13 /* gdal_misc.cpp */
112 #define CTLS_CONFIGOPTIONS 14 /* cpl_conv.cpp */
113 #define CTLS_FINDFILE 15 /* cpl_findfile.cpp */
114 
115 #define CTLS_MAX 32
116 
117 CPL_C_START
118 void CPL_DLL * CPLGetTLS( int nIndex );
119 void CPL_DLL CPLSetTLS( int nIndex, void *pData, int bFreeOnExit );
120 
121 /* Warning : the CPLTLSFreeFunc must not in any case directly or indirectly */
122 /* use or fetch any TLS data, or a terminating thread will hang ! */
123 typedef void (*CPLTLSFreeFunc)( void* pData );
124 void CPL_DLL CPLSetTLSWithFreeFunc( int nIndex, void *pData, CPLTLSFreeFunc pfnFree );
125 
126 void CPL_DLL CPLCleanupTLS();
127 CPL_C_END
128 
129 #endif /* _CPL_MULTIPROC_H_INCLUDED_ */

Generated for GDAL by doxygen 1.8.3.