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 "PsnMemoryManager.h" 00019 00020 #include "PsnMutexLock.h" 00021 #include "PsnNew.h" 00022 #include "PsnSystemMemoryManager.h" 00023 00024 list <PsnMemoryManager *> * PsnMemoryManager::getListOfMemoryManagers() 00025 { 00026 static list <PsnMemoryManager *> designPattern ; 00027 return & designPattern ; 00028 } 00029 00030 PsnMutexLock * PsnMemoryManager::getGlobalListMutex() 00031 { 00032 static PsnMutexLock toto ; 00033 return & toto ; 00034 } 00035 00036 00037 PsnMemoryManager * PsnMemoryManager::whichMemoryManager(void * ptr) 00038 { 00039 PsnMemoryManager * result = NULL ; 00040 getGlobalListMutex()->protect(); 00041 //cerr<<"PsnMemoryManager::whichMemoryManager : getGlobalListMutex()->protect();"<<endl; 00042 list <PsnMemoryManager *>::iterator i = getListOfMemoryManagers()->begin() ; 00043 while ( (result == NULL ) && (i != getListOfMemoryManagers()->end() )) 00044 { 00045 #ifdef _DEBUGMEMORYMANAGEMENT 00046 assert ( (*i)->_isInitialized ) ; 00047 #endif 00048 if ( (*i)->inAdressSpace (ptr) ) 00049 { 00050 result = *i ; 00051 } 00052 else 00053 { 00054 ++i ; 00055 } 00056 } 00057 getGlobalListMutex()->unprotect(); 00058 if ( result == NULL) 00059 { 00060 result = HeapStackTop::getSystemMemoryManager() ; 00061 } 00062 00063 return result ; 00064 } 00065 00066 00067 PsnMemoryManager::~PsnMemoryManager() 00068 { 00069 // do the test, because removal of elements not present seem to bug some implementatiosn of the standard library 00070 if (_isInitialized) 00071 { 00072 getGlobalListMutex()->protect(); 00073 getListOfMemoryManagers()->remove( this ) ; 00074 getGlobalListMutex()->unprotect() ; 00075 } 00076 00077 //when killing the last memory manager, some precautions have to be taken 00078 if ( this == pthread_getspecific( HeapStackTop::globalMemoryManagerKey ) ) 00079 { 00080 pthread_setspecific ( HeapStackTop::globalMemoryManagerKey , NULL ); 00081 } 00082 } 00083 00084 PsnMemoryManager::PsnMemoryManager() : 00085 _isInitialized ( false ) 00086 { 00087 } 00088 00089 void PsnMemoryManager::init() 00090 { 00091 getGlobalListMutex()->protect(); 00092 getListOfMemoryManagers()->push_back( this ) ; 00093 getGlobalListMutex()->unprotect() ; 00094 _isInitialized = true ; 00095 }
| Documentation generated on Mon Nov 25 15:25:00 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |