00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #ifndef PsnSharedMemoryManagerHEADER 00019 #define PsnSharedMemoryManagerHEADER 00020 00021 class PsnMemoryElementDescriptor; 00022 class PsnLock; 00023 00024 #ifdef _PAIRNOTSTD 00025 #include <utility> 00026 #else 00027 #include <pair.h> 00028 #endif 00029 00030 #include <list> 00031 #include "PsnMutexLock.h" 00032 #include "PsnCondition.h" 00033 00039 #ifdef _SGI 00040 #include <stddef.h> 00041 #else 00042 #include <cstddef> 00043 #endif 00044 00045 #include "PsnSystemMemoryManager.h" 00046 00047 class PsnSharedMemoryManager : public PsnMemoryManager 00048 { 00049 public: 00050 00057 PsnSharedMemoryManager(void *startDsm, size_t sizeDsm, size_t pageSize, size_t alignedSize); 00058 00060 virtual ~PsnSharedMemoryManager(); 00061 00062 00063 //------------------------- Allocation and deallocation --------------------// 00064 00065 00068 virtual void *mmalloc (size_t size); 00069 00070 00073 virtual void mfree ( void *addr , size_t size); 00074 00079 virtual void * mfastmalloc(size_t size); 00080 00082 virtual void mfastfree ( void *addr , size_t size); 00083 00085 virtual void *allocateSizeRemembered (size_t size); 00086 00088 virtual void freeSizeRemembered ( void * ptr); 00089 00090 /* handOver : gives back memory associated to an adress. To be used if part of the memory asked for by a client isn't used by the client but cannot be returned at the same time as the rest of the memory allocated. 00091 * @param pointer the pointer associated to the freed memory 00092 * @param allocatedSize the size really used at pointer 00093 * @param sizeBefore the size freed just before the pointer zone 00094 * @param sizeAfter the size free just after the pointer zone */ 00095 virtual void handOver(void * pointer, size_t allocatedSize, size_t sizeBefore, size_t sizeAfter) ; 00096 00097 //-------------------------- lock and unlock -----------------------// 00098 00099 00101 virtual void lockIfNeeded(); 00102 00104 virtual void unlockIfNeeded(); 00105 00106 00107 00108 //-------------------- offset manipulation and validity ------------// 00109 00110 00112 inline unsigned int globalAddressToLocal (void * addr) const { 00113 return ((unsigned int)addr)-_startDsm ; 00114 } 00115 00117 inline void * localAddressToGlobal (unsigned int offset) const { 00118 return (void *)(_startDsm+offset); 00119 } 00120 00125 virtual bool invalidOffset(unsigned int offset) const ; 00126 00128 virtual unsigned int getAnInvalidOffset() const ; 00129 00131 virtual bool inAdressSpace(void * ptr) const 00132 { 00133 unsigned int _ptr=(unsigned int)ptr; 00134 return ((_startDsm<=_ptr)&&(_ptr<_startDsm+_sizeDsm)); 00135 } 00136 00137 00138 //------------------------------------------------------------------// 00139 00140 00142 virtual void sync() = 0 ; 00143 00148 virtual void synchronizeAfterLock(void* beginningAdress, long length) = 0 ; 00149 00150 00152 virtual size_t pageSize() const ; 00153 00155 virtual void showMemory ( void ) ; 00156 00158 virtual bool locked() const ; 00159 00160 protected: 00161 //-----------------------Lock Management internals --------------------// 00162 00164 virtual void lock( ) = 0 ; 00165 00167 virtual void unlock( ) = 0 ; 00168 00170 virtual bool lockNeeded ( ) = 0 ; 00171 00173 unsigned int _numberOfLocks ; 00174 00176 bool _locked ; 00177 00179 pthread_t _lockedBy ; 00180 00182 PsnMutexLock _accessToLockData ; 00183 00185 PsnCondition _conditionOnLocked ; 00186 public: 00187 static PsnMutexLock * mutexCerr ; 00188 //---------------------------------------------------------------------// 00189 00190 protected: 00195 virtual void * getFromFree ( size_t size ) = 0 ; 00196 00201 virtual void addInFree (void *addr, size_t size) = 0 ; 00202 00205 pair<void *,size_t> _freed; 00206 00207 00208 //------------- page size and alignement stuff -----------// 00209 00210 00212 size_t _pageSize; 00213 00215 size_t _alignedSize; 00216 00221 virtual size_t alignedSize(size_t size); 00222 00223 00224 //------ size and starting address of the shared memory -------// 00225 00226 00230 unsigned int _startDsm; 00231 00233 unsigned int _sizeDsm; 00234 00235 }; 00236 00237 #endif 00238 00239 00240 00241 00242 00243 00244
| Documentation generated on Mon Nov 25 15:25:01 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |