cpl_multiproc.h

00001 /**********************************************************************
00002  * $Id: cpl_multiproc.h 11525 2007-05-15 17:28:31Z warmerdam $
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 // There are three primary implementations of the multi-process support
00036 // controlled by one of CPL_MULTIPROC_WIN32, CPL_MULTIPROC_PTHREAD or
00037 // CPL_MULTIPROC_STUB being defined.  If none are defined, the stub
00038 // implementation will be used.
00039 
00040 #if defined(WIN32) && !defined(CPL_MULTIPROC_STUB)
00041 #  define CPL_MULTIPROC_WIN32
00042 #endif
00043 
00044 #if !defined(CPL_MULTIPROC_WIN32) && !defined(CPL_MULTIPROC_PTHREAD) \
00045  && !defined(CPL_MULTIPROC_STUB) && !defined(CPL_MULTIPROC_NONE)
00046 #  define CPL_MULTIPROC_STUB
00047 #endif
00048 
00049 CPL_C_START
00050 
00051 typedef void (*CPLThreadFunc)(void *);
00052 
00053 void CPL_DLL *CPLLockFile( const char *pszPath, double dfWaitInSeconds );
00054 void  CPL_DLL CPLUnlockFile( void *hLock );
00055 
00056 void CPL_DLL *CPLCreateMutex();
00057 int   CPL_DLL CPLCreateOrAcquireMutex( void **, double dfWaitInSeconds );
00058 int   CPL_DLL CPLAcquireMutex( void *hMutex, double dfWaitInSeconds );
00059 void  CPL_DLL CPLReleaseMutex( void *hMutex );
00060 void  CPL_DLL CPLDestroyMutex( void *hMutex );
00061 
00062 int   CPL_DLL CPLGetPID();
00063 int   CPL_DLL CPLCreateThread( CPLThreadFunc pfnMain, void *pArg );
00064 void  CPL_DLL CPLSleep( double dfWaitInSeconds );
00065 
00066 const char CPL_DLL *CPLGetThreadingModel();
00067 
00068 CPL_C_END
00069 
00070 #ifdef __cplusplus
00071 
00072 #define CPLMutexHolderD(x)  CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__);
00073 
00074 class CPL_DLL CPLMutexHolder
00075 {
00076   private:
00077     void       *hMutex;
00078     const char *pszFile;
00079     int         nLine;
00080 
00081   public:
00082 
00083     CPLMutexHolder( void **phMutex, double dfWaitInSeconds = 1000.0,
00084                     const char *pszFile = __FILE__,
00085                     int nLine = __LINE__ );
00086     ~CPLMutexHolder();
00087 };
00088 #endif /* def __cplusplus */
00089 
00090 /* -------------------------------------------------------------------- */
00091 /*      Thread local storage.                                           */
00092 /* -------------------------------------------------------------------- */
00093 
00094 #define CTLS_RLBUFFERINFO               1         /* cpl_conv.cpp */
00095 #define CTLS_DECDMSBUFFER               2         /* cpl_conv.cpp */
00096 #define CTLS_CSVTABLEPTR                3         /* cpl_csv.cpp */
00097 #define CTLS_CSVDEFAULTFILENAME         4         /* cpl_csv.cpp */
00098 #define CTLS_ERRORCONTEXT               5         /* cpl_error.cpp */
00099 #define CTLS_FINDERINFO                 6         /* cpl_finder.cpp */
00100 #define CTLS_PATHBUF                    7         /* cpl_path.cpp */
00101 #define CTLS_SPRINTFBUF                 8         /* cpl_string.cpp */
00102 
00103 #define CTLS_MAX                       32         
00104 
00105 CPL_C_START
00106 void CPL_DLL * CPLGetTLS( int nIndex );
00107 void CPL_DLL CPLSetTLS( int nIndex, void *pData, int bFreeOnExit );
00108 void CPL_DLL CPLCleanupTLS();
00109 CPL_C_END
00110 
00111 #endif /* _CPL_MULTIPROC_H_INCLUDED_ */

Generated for GDAL by doxygen 1.4.7.