Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsnMemoryManager Class Reference

The base abstract class of all memory managers in the system. More...

#include <PsnMemoryManager.h>

Inheritance diagram for PsnMemoryManager:

Inheritance graph
[legend]
List of all members.

Public Methods

virtual ~PsnMemoryManager ()
 destructor

 PsnMemoryManager ()
 constructor

void init ()
 declare the memory manager to the memory management subsystem.

virtual void * allocateSizeRemembered (size_t size)=0
 alloc a memory zone that can be correctly freed by calling freeSizeRemembered with the resulting pointer

virtual void freeSizeRemembered (void *ptr)=0
 free a memory zone allocated with allocateSizeRemembered

virtual bool inAdressSpace (void *ptr) const=0
 find out if a given adress is managed by the current memory manager


Static Public Methods

PsnMemoryManager * whichMemoryManager (void *)
 Find which was the first memory manager to declare managing memory at a given adress.


Static Protected Methods

list< PsnMemoryManager * > * getListOfMemoryManagers ()
 the list of memory managers created in the current address space

PsnMutexLockgetGlobalListMutex ()
 the lock to protect access to the global list of memory managers


Protected Attributes

bool _isInitialized
 isInitialized.


Detailed Description

The base abstract class of all memory managers in the system.

Author:
David Margery
Version:
1.0 (revision $revision$ )

Definition at line 33 of file PsnMemoryManager.h.


Constructor & Destructor Documentation

PsnMemoryManager::~PsnMemoryManager   [virtual]
 

destructor

Definition at line 67 of file PsnMemoryManager.cxx.

References getGlobalListMutex(), getListOfMemoryManagers(), HeapStackTop::globalMemoryManagerKey, PsnMutexLock::protect(), and PsnMutexLock::unprotect().

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 }

PsnMemoryManager::PsnMemoryManager  
 

constructor

Definition at line 84 of file PsnMemoryManager.cxx.

00084                                    :
00085    _isInitialized ( false )
00086 {
00087 }


Member Function Documentation

virtual void* PsnMemoryManager::allocateSizeRemembered size_t    size [pure virtual]
 

alloc a memory zone that can be correctly freed by calling freeSizeRemembered with the resulting pointer

Implemented in PsnDescriptorMemoryManager, PsnRelaxedMemoryManager, PsnSharedMemoryManager, PsnSystemMemoryManager, and PsnThreadMemoryManager.

Referenced by PsnMultiThreadedScheduler::_threadContainer(), PsnMultiThreadedBenchmarkingScheduler::_threadContainer(), PsnThreadMemoryManager::allocateSizeRemembered(), PsnDescriptorMemoryManager::allocateSizeRemembered(), PsnMemoryElementDescriptor::operator new(), PsnDescriptorMemoryManager::PsnDescriptorMemoryManager(), and PsMultiThreadedController::run().

virtual void PsnMemoryManager::freeSizeRemembered void *    ptr [pure virtual]
 

free a memory zone allocated with allocateSizeRemembered

Implemented in PsnDescriptorMemoryManager, PsnRelaxedMemoryManager, PsnSharedMemoryManager, PsnSystemMemoryManager, and PsnThreadMemoryManager.

Referenced by PsnThreadMemoryManager::freeLeakedMemoryBlocks(), PsnThreadMemoryManager::freeSizeRemembered(), PsnSystemMemoryManager::freeSizeRemembered(), PsnSharedMemoryManager::freeSizeRemembered(), operator delete(), and PsnMemoryElementDescriptor::operator delete().

PsnMutexLock * PsnMemoryManager::getGlobalListMutex   [static, protected]
 

the lock to protect access to the global list of memory managers

Definition at line 30 of file PsnMemoryManager.cxx.

Referenced by init(), whichMemoryManager(), and ~PsnMemoryManager().

00031 {
00032    static PsnMutexLock toto ;
00033    return & toto ;
00034 }

list< PsnMemoryManager * > * PsnMemoryManager::getListOfMemoryManagers   [static, protected]
 

the list of memory managers created in the current address space

Definition at line 24 of file PsnMemoryManager.cxx.

Referenced by init(), whichMemoryManager(), and ~PsnMemoryManager().

00025 {
00026    static list <PsnMemoryManager *> designPattern ; 
00027    return & designPattern ;
00028 }

virtual bool PsnMemoryManager::inAdressSpace void *    ptr const [pure virtual]
 

find out if a given adress is managed by the current memory manager

Implemented in PsnDescriptorMemoryManager, PsnSharedMemoryManager, PsnSystemMemoryManager, and PsnThreadMemoryManager.

Referenced by PsnThreadMemoryManager::freeSizeRemembered().

void PsnMemoryManager::init  
 

declare the memory manager to the memory management subsystem.

This declaration cannot be made in the constructor, because in multi-threaded environments, it would enable the memory management subsystem to try and use a memory manager still under construction.

Definition at line 89 of file PsnMemoryManager.cxx.

References _isInitialized, getGlobalListMutex(), getListOfMemoryManagers(), PsnMutexLock::protect(), and PsnMutexLock::unprotect().

Referenced by PsnMultiThreadedScheduler::_threadContainer(), PsnMultiThreadedBenchmarkingScheduler::_threadContainer(), and PsMultiThreadedController::run().

00090 {
00091    getGlobalListMutex()->protect();   
00092    getListOfMemoryManagers()->push_back( this ) ;
00093    getGlobalListMutex()->unprotect() ;
00094    _isInitialized = true ;
00095 }

PsnMemoryManager * PsnMemoryManager::whichMemoryManager void *    [static]
 

Find which was the first memory manager to declare managing memory at a given adress.

Definition at line 37 of file PsnMemoryManager.cxx.

References getGlobalListMutex(), getListOfMemoryManagers(), HeapStackTop::getSystemMemoryManager(), PsnMutexLock::protect(), and PsnMutexLock::unprotect().

Referenced by PsnThreadMemoryManager::freeLeakedMemoryBlocks(), PsnSystemMemoryManager::freeSizeRemembered(), PsnSharedMemoryManager::freeSizeRemembered(), PsnMomeArray< T >::operator delete(), PsnMomeReaderFifo< Type >::printDebuggingInformation(), and PsnMomeArray< T >::~PsnMomeArray().

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 }


Member Data Documentation

bool PsnMemoryManager::_isInitialized [protected]
 

isInitialized.

when the _DEBUGMEMORYMANAGEMENT compilation flag is set, is tested by the memory management subsystem to make sure init was called

Definition at line 62 of file PsnMemoryManager.h.

Referenced by init().


The documentation for this class was generated from the following files:
logo OpenMask

Documentation generated on Mon Nov 25 15:26:08 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001