OGR
cpl_multiproc.h
1 /**********************************************************************
2  * $Id: cpl_multiproc.h 20088 2010-07-17 20:41: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 #endif
45 
46 #if !defined(CPL_MULTIPROC_WIN32) && !defined(CPL_MULTIPROC_PTHREAD) \
47  && !defined(CPL_MULTIPROC_STUB) && !defined(CPL_MULTIPROC_NONE)
48 # define CPL_MULTIPROC_STUB
49 #endif
50 
51 CPL_C_START
52 
53 typedef void (*CPLThreadFunc)(void *);
54 
55 void CPL_DLL *CPLLockFile( const char *pszPath, double dfWaitInSeconds );
56 void CPL_DLL CPLUnlockFile( void *hLock );
57 
58 void CPL_DLL *CPLCreateMutex();
59 int CPL_DLL CPLCreateOrAcquireMutex( void **, double dfWaitInSeconds );
60 int CPL_DLL CPLAcquireMutex( void *hMutex, double dfWaitInSeconds );
61 void CPL_DLL CPLReleaseMutex( void *hMutex );
62 void CPL_DLL CPLDestroyMutex( void *hMutex );
63 
64 GIntBig CPL_DLL CPLGetPID();
65 int CPL_DLL CPLCreateThread( CPLThreadFunc pfnMain, void *pArg );
66 void CPL_DLL CPLSleep( double dfWaitInSeconds );
67 
68 const char CPL_DLL *CPLGetThreadingModel();
69 
70 CPL_C_END
71 
72 #ifdef __cplusplus
73 
74 #define CPLMutexHolderD(x) CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__);
75 
76 class CPL_DLL CPLMutexHolder
77 {
78  private:
79  void *hMutex;
80  const char *pszFile;
81  int nLine;
82 
83  public:
84 
85  CPLMutexHolder( void **phMutex, double dfWaitInSeconds = 1000.0,
86  const char *pszFile = __FILE__,
87  int nLine = __LINE__ );
88  ~CPLMutexHolder();
89 };
90 #endif /* def __cplusplus */
91 
92 /* -------------------------------------------------------------------- */
93 /* Thread local storage. */
94 /* -------------------------------------------------------------------- */
95 
96 #define CTLS_RLBUFFERINFO 1 /* cpl_conv.cpp */
97 #define CTLS_DECDMSBUFFER 2 /* cpl_conv.cpp */
98 #define CTLS_CSVTABLEPTR 3 /* cpl_csv.cpp */
99 #define CTLS_CSVDEFAULTFILENAME 4 /* cpl_csv.cpp */
100 #define CTLS_ERRORCONTEXT 5 /* cpl_error.cpp */
101 #define CTLS_UNUSED1 6
102 #define CTLS_PATHBUF 7 /* cpl_path.cpp */
103 #define CTLS_SPRINTFBUF 8 /* cpl_string.cpp */
104 #define CTLS_SWQ_ERRBUF 9 /* swq.c */
105 #define CTLS_CPLSPRINTF 10 /* cpl_string.h */
106 #define CTLS_RESPONSIBLEPID 11 /* gdaldataset.cpp */
107 #define CTLS_VERSIONINFO 12 /* gdal_misc.cpp */
108 #define CTLS_VERSIONINFO_LICENCE 13 /* gdal_misc.cpp */
109 #define CTLS_CONFIGOPTIONS 14 /* cpl_conv.cpp */
110 #define CTLS_FINDFILE 15 /* cpl_findfile.cpp */
111 
112 #define CTLS_MAX 32
113 
114 CPL_C_START
115 void CPL_DLL * CPLGetTLS( int nIndex );
116 void CPL_DLL CPLSetTLS( int nIndex, void *pData, int bFreeOnExit );
117 
118 /* Warning : the CPLTLSFreeFunc must not in any case directly or indirectly */
119 /* use or fetch any TLS data, or a terminating thread will hang ! */
120 typedef void (*CPLTLSFreeFunc)( void* pData );
121 void CPL_DLL CPLSetTLSWithFreeFunc( int nIndex, void *pData, CPLTLSFreeFunc pfnFree );
122 
123 void CPL_DLL CPLCleanupTLS();
124 CPL_C_END
125 
126 #endif /* _CPL_MULTIPROC_H_INCLUDED_ */

Generated for GDAL by doxygen 1.8.4.