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 #include "PsnSecondarySharedMemoryManager.h" 00019 00020 #include "PsnMemoryElementDescriptor.h" 00021 #include "PsnRelaxedMemoryManager.h" 00022 00023 PsnSecondarySharedMemoryManager::PsnSecondarySharedMemoryManager(size_t sizeDsm, size_t pageSize, size_t alignedSize, PsnRelaxedMemoryManager & memoryManager) : 00024 PsnSharedMemoryManager(memoryManager.mmalloc(sizeDsm / pageSize), 00025 sizeDsm, 00026 pageSize, 00027 alignedSize), 00028 _myMemoryManager(memoryManager) 00029 { 00030 #ifdef _DEBUGALLOCATIONMOME 00031 cerr<<sizeDsm<<" "<<pageSize<<endl; 00032 #endif 00033 assert(sizeDsm % pageSize == 0) ; 00034 00035 _firstPageOffset = _myMemoryManager.globalAddressToLocal((void *)_startDsm) / _pageSize ; 00036 } 00037 00038 PsnSecondarySharedMemoryManager::~PsnSecondarySharedMemoryManager() { 00039 00040 } 00041 00042 00043 void PsnSecondarySharedMemoryManager::sync() { 00044 //cerr<<"PsnSecondarySharedMemoryManager::sync"<<endl; 00045 } 00046 00047 void * PsnSecondarySharedMemoryManager::getFromThisFree ( PsnMemoryElementDescriptor * * startFreeList, size_t size ) { 00048 PsnMemoryElementDescriptor *i , *pred ; 00049 00050 unsigned int addr ; 00051 00052 #ifdef _DEBUGALLOCATIONMOME 00053 if (*startFreeList != NULL ) { 00054 cerr<<"PsnSecondarySharedMemoryManager::getFromThisFree "<<startFreeList<<" " 00055 <<(*startFreeList)->base<<" " 00056 <<(*startFreeList)->next<<" " 00057 <<(*startFreeList)->size<<endl; 00058 } 00059 #endif 00060 00061 i = * startFreeList ; 00062 00063 pred = NULL ; 00064 00065 addr = getAnInvalidOffset() ; 00066 00067 while ( i != NULL ) 00068 { 00069 if ( i->size >= size ) /* First fit strategy */ 00070 { 00071 addr = i->base ; 00072 if ( i->size == size ) 00073 { 00074 if ( pred == NULL ) { 00075 PsnMemoryElementDescriptor * newStartFreeList = (PsnMemoryElementDescriptor *) i -> next ; 00076 delete *startFreeList ; 00077 *startFreeList = newStartFreeList ; 00078 //cerr<<*startFreeList<<endl; 00079 } 00080 else { 00081 pred->next = i->next ; 00082 delete ( i ) ; 00083 } 00084 } 00085 else 00086 { 00087 i->base = i->base + size ; 00088 i->size = i->size - size ; 00089 } 00090 i = NULL ; 00091 } 00092 else 00093 { 00094 pred = i ; 00095 i = (PsnMemoryElementDescriptor *) i->next ; 00096 } 00097 } 00098 if (invalidOffset(addr) ) 00099 { 00100 return NULL ; 00101 //cerr<<"PsnSecondarySharedMemoryManager::getFromThisFree : returning NULL"<<endl 00102 } 00103 else { 00104 00105 return localAddressToGlobal(addr) ; 00106 } 00107 00108 } 00109 00110 00111 00112 void PsnSecondarySharedMemoryManager::addInThisFree (PsnMemoryElementDescriptor * * startFreeList, unsigned int base, size_t size) { 00113 00114 //cerr<<"PsnSecondarySharedMemoryManager::addInThisFree "<<startFreeList<<endl; 00115 PsnMemoryElementDescriptor *l, *iNew, *tmp ; 00116 00117 iNew= new PsnMemoryElementDescriptor(); 00118 iNew->base = base ; 00119 iNew->size = size; 00120 00121 if ( * startFreeList == NULL) { /* Empty list */ 00122 iNew->next = (unsigned int) NULL ; 00123 *startFreeList = iNew ; 00124 } 00125 else { 00126 l = *startFreeList ; 00127 if ( l->base > iNew->base ) { /* iNew is the lowest interval */ 00128 iNew->next = (unsigned int) * startFreeList ; 00129 *startFreeList = iNew ; 00130 //reorder so that l->next == iNew for merge test 00131 l = iNew ; 00132 iNew = (PsnMemoryElementDescriptor *) l->next ; 00133 } 00134 else { /* Search the immediate lower interval */ 00135 tmp = (PsnMemoryElementDescriptor * ) l -> next ; 00136 bool onBoucle = tmp != NULL ; 00137 if (onBoucle ) onBoucle = ( iNew->base > tmp->base ) ; 00138 while ( onBoucle ) { 00139 l = tmp ; 00140 tmp = (PsnMemoryElementDescriptor * ) l->next ; 00141 if (tmp != NULL) { 00142 onBoucle = iNew->base > tmp->base ; 00143 } 00144 else onBoucle = false ; 00145 } 00146 iNew->next = (unsigned int) tmp ; 00147 l->next = (unsigned int) iNew ; 00148 if ( tmp != NULL ) { 00149 if (iNew->base + iNew->size == tmp -> base) { 00150 iNew->size += tmp->size ; 00151 iNew->next = tmp->next ; 00152 delete tmp ; 00153 } 00154 } 00155 } 00156 if ( l->base + l->size == iNew->base ) { 00157 l->size += iNew->size ; 00158 l->next = iNew->next ; 00159 if (*startFreeList == iNew) *startFreeList = l; 00160 delete iNew ; 00161 } 00162 } 00163 } 00164 00165 00166 void PsnSecondarySharedMemoryManager::lock() { 00167 // nothing to do because lockIfNeeded protects local access (thread access) if lockNeeded returns true 00168 #ifdef _DEBUGLOCK 00169 cerr<<"-"; 00170 #endif 00171 } 00172 00173 void PsnSecondarySharedMemoryManager::unlock() { 00174 #ifdef _DEBUGLOCK 00175 cerr<<"-"; 00176 #endif 00177 } 00178 00179 bool PsnSecondarySharedMemoryManager::lockNeeded() { 00180 return true ; 00181 } 00182 00183 void PsnSecondarySharedMemoryManager::synchronizeAfterLock(void *, long int) { 00184 //nothing to do. 00185 }
| Documentation generated on Mon Nov 25 15:25:01 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |