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

PsnMemoryElementDescriptor.cxx

Go to the documentation of this file.
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 "PsnMemoryElementDescriptor.h"
00019 #include "PsnMemoryManager.h"
00020 #include "PsnSharedMemoryManager.h"
00021 #include "PsnNew.h"
00022 #ifdef _MOME
00023 #include <PsMomeController.h>
00024 #endif
00025 #include <iostream>
00026 #include <malloc.h>
00027 #include <assert.h>
00028 
00029 
00030 PsnMemoryElementDescriptor::PsnMemoryElementDescriptor()
00031 {
00032    //cerr<<"PsnMemoryElementDescriptor::PsnMemoryElementDescriptor : constructeur vide"<<endl;
00033 }
00034 
00035 PsnMemoryElementDescriptor::PsnMemoryElementDescriptor(const PsnMemoryElementDescriptor & original) :
00036    base(original.base),
00037    size(original.size),
00038    next(original.next)
00039 {
00040 
00041 }
00042 
00043 
00044 void * PsnMemoryElementDescriptor::operator new (size_t size, void * here ) {
00045    return here ;
00046 }
00047 
00048 
00049 
00050 void * PsnMemoryElementDescriptor::operator new (size_t size, PsnMemoryManager * memoryManager ) 
00051 {
00052    assert ( memoryManager != NULL) ;
00053    assert ( dynamic_cast<PsnSharedMemoryManager *> (memoryManager) == NULL ) ;
00054 
00055    return memoryManager->allocateSizeRemembered (size) ;
00056 }
00057 
00058 
00059 
00060 void * PsnMemoryElementDescriptor::operator new (size_t size, PsnSharedMemoryManager * memoryManager ) 
00061 {
00063    if (memoryManager != 0) 
00064       {
00065 #ifdef _MOME
00066          assert(dynamic_cast<PsnRelaxedMemoryManager *>(memoryManager) == NULL) ;
00067 #endif
00068          return memoryManager->mmalloc(size);
00069       }
00070    else 
00071       {
00072          return HeapStackTop::getSystemMemoryManager()->allocateSizeRemembered (size)  ;
00073       }
00074 }
00075 
00076 
00077 
00078 void PsnMemoryElementDescriptor::operator delete(void* addr, size_t size) 
00079 {
00080 #ifdef _DEBUGMEMORYMANAGEMENT
00081    cerr<<"PsnMemoryElementDescriptor::operator delete"<<endl;
00082 #endif
00083    
00084    PsnMemoryManager * freeFrom = (PsnMemoryManager *) (pthread_getspecific( HeapStackTop::globalMemoryManagerKey ) );
00085    
00086 #ifdef _DEBUGMEMORYMANAGEMENT
00087    assert ( freeFrom != NULL ) ;
00088 #endif
00089 
00090    PsnSharedMemoryManager * freeFromShared = dynamic_cast<PsnSharedMemoryManager *> (freeFrom) ;
00091 
00092    if ( freeFromShared != NULL )
00093       {
00094 #ifdef _MOME
00095          assert(dynamic_cast<PsnRelaxedMemoryManager *>(freeFrom) == NULL) ;
00096 #endif   
00097          freeFromShared->lockIfNeeded();
00098          
00099          freeFromShared->mfree( addr , size ) ;
00100          
00101          freeFromShared->unlockIfNeeded();
00102       }
00103    else
00104       {
00105          freeFrom->freeSizeRemembered ( addr ) ;
00106       }
00107 #ifdef _DEBUGALLOCATIONMOME
00108    cerr<<"PsnMemoryElementDescriptor::operator delete done"<<endl;
00109 #endif
00110 }
00111 

logo OpenMask

Documentation generated on Mon Nov 25 15:25:00 2002

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