00001 /********************************************************************** 00002 * $Id: cpl_multiproc.h,v 1.9 2005/08/24 22:19:27 fwarmerdam Exp $ 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 * $Log: cpl_multiproc.h,v $ 00031 * Revision 1.9 2005/08/24 22:19:27 fwarmerdam 00032 * added CPLCleanupTLS 00033 * 00034 * Revision 1.8 2005/07/08 18:17:52 fwarmerdam 00035 * complete TLS implementation for win32 00036 * 00037 * Revision 1.7 2005/07/08 14:35:26 fwarmerdam 00038 * preliminary TLS support 00039 * 00040 * Revision 1.6 2005/05/23 06:39:49 fwarmerdam 00041 * added CPLMutexHolder stuff 00042 * 00043 * Revision 1.5 2005/05/20 19:19:00 fwarmerdam 00044 * added CPLCreateOrAcquireMutex() 00045 * 00046 * Revision 1.4 2005/04/26 20:52:10 fwarmerdam 00047 * use a typedef type for thread mains (for Sun port) 00048 * 00049 * Revision 1.3 2003/04/23 04:36:55 warmerda 00050 * pthreads based implementation 00051 * 00052 * Revision 1.2 2002/05/24 04:09:24 warmerda 00053 * fixed CPL_DLL declarations 00054 * 00055 * Revision 1.1 2002/05/24 04:01:01 warmerda 00056 * New 00057 * 00058 **********************************************************************/ 00059 00060 #ifndef _CPL_MULTIPROC_H_INCLUDED_ 00061 #define _CPL_MULTIPROC_H_INCLUDED_ 00062 00063 #include "cpl_port.h" 00064 00065 // There are three primary implementations of the multi-process support 00066 // controlled by one of CPL_MULTIPROC_WIN32, CPL_MULTIPROC_PTHREAD or 00067 // CPL_MULTIPROC_STUB being defined. If none are defined, the stub 00068 // implementation will be used. 00069 00070 #if defined(WIN32) && !defined(CPL_MULTIPROC_STUB) 00071 # define CPL_MULTIPROC_WIN32 00072 #endif 00073 00074 #if !defined(CPL_MULTIPROC_WIN32) && !defined(CPL_MULTIPROC_PTHREAD) \ 00075 && !defined(CPL_MULTIPROC_STUB) 00076 # define CPL_MULTIPROC_STUB 00077 #endif 00078 00079 CPL_C_START 00080 00081 typedef void (*CPLThreadFunc)(void *); 00082 00083 void CPL_DLL *CPLLockFile( const char *pszPath, double dfWaitInSeconds ); 00084 void CPL_DLL CPLUnlockFile( void *hLock ); 00085 00086 void CPL_DLL *CPLCreateMutex(); 00087 int CPL_DLL CPLCreateOrAcquireMutex( void **, double dfWaitInSeconds ); 00088 int CPL_DLL CPLAcquireMutex( void *hMutex, double dfWaitInSeconds ); 00089 void CPL_DLL CPLReleaseMutex( void *hMutex ); 00090 void CPL_DLL CPLDestroyMutex( void *hMutex ); 00091 00092 int CPL_DLL CPLGetPID(); 00093 int CPL_DLL CPLCreateThread( CPLThreadFunc pfnMain, void *pArg ); 00094 void CPL_DLL CPLSleep( double dfWaitInSeconds ); 00095 00096 const char CPL_DLL *CPLGetThreadingModel(); 00097 00098 CPL_C_END 00099 00100 #ifdef __cplusplus 00101 00102 #define CPLMutexHolderD(x) CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__); 00103 00104 class CPLMutexHolder 00105 { 00106 private: 00107 void *hMutex; 00108 const char *pszFile; 00109 int nLine; 00110 00111 public: 00112 00113 CPLMutexHolder( void **phMutex, double dfWaitInSeconds = 1000.0, 00114 const char *pszFile = __FILE__, 00115 int nLine = __LINE__ ); 00116 ~CPLMutexHolder(); 00117 }; 00118 #endif /* def __cplusplus */ 00119 00120 /* -------------------------------------------------------------------- */ 00121 /* Thread local storage. */ 00122 /* -------------------------------------------------------------------- */ 00123 00124 #define CTLS_RLBUFFERINFO 1 /* cpl_conv.cpp */ 00125 #define CTLS_DECDMSBUFFER 2 /* cpl_conv.cpp */ 00126 #define CTLS_CSVTABLEPTR 3 /* cpl_csv.cpp */ 00127 #define CTLS_CSVDEFAULTFILENAME 4 /* cpl_csv.cpp */ 00128 #define CTLS_ERRORCONTEXT 5 /* cpl_error.cpp */ 00129 #define CTLS_FINDERINFO 6 /* cpl_finder.cpp */ 00130 #define CTLS_PATHBUF 7 /* cpl_path.cpp */ 00131 #define CTLS_SPRINTFBUF 8 /* cpl_string.cpp */ 00132 00133 #define CTLS_MAX 32 00134 00135 CPL_C_START 00136 void CPL_DLL * CPLGetTLS( int nIndex ); 00137 void CPL_DLL CPLSetTLS( int nIndex, void *pData, int bFreeOnExit ); 00138 void CPL_DLL CPLCleanupTLS(); 00139 CPL_C_END 00140 00141 #endif /* _CPL_MULTIPROC_H_INCLUDED_ */