GDAL
cpl_multiproc.h
00001 /**********************************************************************
00002  * $Id: cpl_multiproc.h 25716 2013-03-09 12:09:29Z rouault $
00003  *
00004  * Project:  CPL - Common Portability Library
00005  * Purpose:  CPL Multi-Threading, and process handling portability functions.
00006  * Author:   Frank Warmerdam, warmerdam@pobox.com
00007  *
00008  **********************************************************************
00009  * Copyright (c) 2002, Frank Warmerdam
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a
00012  * copy of this software and associated documentation files (the "Software"),
00013  * to deal in the Software without restriction, including without limitation
00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00015  * and/or sell copies of the Software, and to permit persons to whom the
00016  * Software is furnished to do so, subject to the following conditions:
00017  * 
00018  * The above copyright notice and this permission notice shall be included
00019  * in all copies or substantial portions of the Software.
00020  * 
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00022  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
00027  * DEALINGS IN THE SOFTWARE.
00028  ****************************************************************************/
00029 
00030 #ifndef _CPL_MULTIPROC_H_INCLUDED_
00031 #define _CPL_MULTIPROC_H_INCLUDED_
00032 
00033 #include "cpl_port.h"
00034 
00035 /*
00036 ** There are three primary implementations of the multi-process support
00037 ** controlled by one of CPL_MULTIPROC_WIN32, CPL_MULTIPROC_PTHREAD or
00038 ** CPL_MULTIPROC_STUB being defined.  If none are defined, the stub
00039 ** implementation will be used.
00040 */
00041 
00042 #if defined(WIN32) && !defined(CPL_MULTIPROC_STUB)
00043 #  define CPL_MULTIPROC_WIN32
00044 /* MinGW can have pthread support, so disable it to avoid issues */
00045 /* in cpl_multiproc.cpp */
00046 #  undef  CPL_MULTIPROC_PTHREAD
00047 #endif
00048 
00049 #if !defined(CPL_MULTIPROC_WIN32) && !defined(CPL_MULTIPROC_PTHREAD) \
00050  && !defined(CPL_MULTIPROC_STUB) && !defined(CPL_MULTIPROC_NONE)
00051 #  define CPL_MULTIPROC_STUB
00052 #endif
00053 
00054 CPL_C_START
00055 
00056 typedef void (*CPLThreadFunc)(void *);
00057 
00058 void CPL_DLL *CPLLockFile( const char *pszPath, double dfWaitInSeconds );
00059 void  CPL_DLL CPLUnlockFile( void *hLock );
00060 
00061 void CPL_DLL *CPLCreateMutex();
00062 int   CPL_DLL CPLCreateOrAcquireMutex( void **, double dfWaitInSeconds );
00063 int   CPL_DLL CPLAcquireMutex( void *hMutex, double dfWaitInSeconds );
00064 void  CPL_DLL CPLReleaseMutex( void *hMutex );
00065 void  CPL_DLL CPLDestroyMutex( void *hMutex );
00066 void  CPL_DLL CPLCleanupMasterMutex();
00067 
00068 void  CPL_DLL *CPLCreateCond();
00069 void  CPL_DLL  CPLCondWait( void *hCond, void* hMutex );
00070 void  CPL_DLL  CPLCondSignal( void *hCond );
00071 void  CPL_DLL  CPLCondBroadcast( void *hCond );
00072 void  CPL_DLL  CPLDestroyCond( void *hCond );
00073 
00074 GIntBig CPL_DLL CPLGetPID();
00075 int   CPL_DLL CPLCreateThread( CPLThreadFunc pfnMain, void *pArg );
00076 void  CPL_DLL* CPLCreateJoinableThread( CPLThreadFunc pfnMain, void *pArg );
00077 void  CPL_DLL CPLJoinThread(void* hJoinableThread); 
00078 void  CPL_DLL CPLSleep( double dfWaitInSeconds );
00079 
00080 const char CPL_DLL *CPLGetThreadingModel();
00081 
00082 int CPL_DLL CPLGetNumCPUs();
00083 
00084 CPL_C_END
00085 
00086 #ifdef __cplusplus
00087 
00088 #define CPLMutexHolderD(x)  CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__);
00089 
00090 class CPL_DLL CPLMutexHolder
00091 {
00092   private:
00093     void       *hMutex;
00094     const char *pszFile;
00095     int         nLine;
00096 
00097   public:
00098 
00099     CPLMutexHolder( void **phMutex, double dfWaitInSeconds = 1000.0,
00100                     const char *pszFile = __FILE__,
00101                     int nLine = __LINE__ );
00102     ~CPLMutexHolder();
00103 };
00104 #endif /* def __cplusplus */
00105 
00106 /* -------------------------------------------------------------------- */
00107 /*      Thread local storage.                                           */
00108 /* -------------------------------------------------------------------- */
00109 
00110 #define CTLS_RLBUFFERINFO               1         /* cpl_conv.cpp */
00111 #define CTLS_WIN32_COND                 2         /* cpl_multiproc.cpp */
00112 #define CTLS_CSVTABLEPTR                3         /* cpl_csv.cpp */
00113 #define CTLS_CSVDEFAULTFILENAME         4         /* cpl_csv.cpp */
00114 #define CTLS_ERRORCONTEXT               5         /* cpl_error.cpp */
00115 #define CTLS_GDALDATASET_REC_PROTECT_MAP 6        /* gdaldataset.cpp */
00116 #define CTLS_PATHBUF                    7         /* cpl_path.cpp */
00117 #define CTLS_UNUSED3                    8
00118 #define CTLS_UNUSED4                    9
00119 #define CTLS_CPLSPRINTF                10         /* cpl_string.h */
00120 #define CTLS_RESPONSIBLEPID            11         /* gdaldataset.cpp */
00121 #define CTLS_VERSIONINFO               12         /* gdal_misc.cpp */
00122 #define CTLS_VERSIONINFO_LICENCE       13         /* gdal_misc.cpp */
00123 #define CTLS_CONFIGOPTIONS             14         /* cpl_conv.cpp */
00124 #define CTLS_FINDFILE                  15         /* cpl_findfile.cpp */
00125 
00126 #define CTLS_MAX                       32         
00127 
00128 CPL_C_START
00129 void CPL_DLL * CPLGetTLS( int nIndex );
00130 void CPL_DLL CPLSetTLS( int nIndex, void *pData, int bFreeOnExit );
00131 
00132 /* Warning : the CPLTLSFreeFunc must not in any case directly or indirectly */
00133 /* use or fetch any TLS data, or a terminating thread will hang ! */
00134 typedef void (*CPLTLSFreeFunc)( void* pData );
00135 void CPL_DLL CPLSetTLSWithFreeFunc( int nIndex, void *pData, CPLTLSFreeFunc pfnFree );
00136 
00137 void CPL_DLL CPLCleanupTLS();
00138 CPL_C_END
00139 
00140 #endif /* _CPL_MULTIPROC_H_INCLUDED_ */

Generated for GDAL by doxygen 1.7.6.1.