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

PsnSharedFreeStoreMemoryManager.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 "PsnSharedFreeStoreMemoryManager.h"
00019 #include "PsnRelaxedMemoryManager.h"
00020 #include "PsnMemoryElementDescriptor.h"
00021 
00022 
00023 PsnSharedFreeStoreMemoryManager::PsnSharedFreeStoreMemoryManager(size_t sizeDsm, size_t pageSize, size_t alignedSize, PsnRelaxedMemoryManager & memoryManager, int queueSize) : 
00024    PsnFramedMemoryManager(sizeDsm,
00025                           pageSize, 
00026                           alignedSize, 
00027                           memoryManager, 
00028                           queueSize)
00029 {
00030    //cerr<<"gestion des adresses entre "<<(void *)_startDsm<<" et "<<(void *)(_startDsm+_sizeDsm)<<endl;
00031    _tabLibres = new PsnMemoryElementDescriptor * [ _queueSize ] ;
00032 
00033    _tabTailleLibre = new size_t [ _queueSize ] ;
00034    int * toto ;
00035    for (int i = 0 ; i < _queueSize ; i++ ) {
00036       _tabLibres [ i ] = new PsnMemoryElementDescriptor() ;
00037       _tabLibres [ i ]->base = i * _blockSize ;
00038       _tabLibres [ i ]->size = _blockSize ; 
00039       _tabLibres [ i ]->next = (unsigned int) NULL ;
00040       _tabTailleLibre [ i ] = _blockSize ;
00041       assert(_blockSize == _pageSize) ; //for rapid prototyping
00042       //write something on every page so that prefetch will work
00043       toto = (int *)(_startDsm + i * _pageSize) ;
00044       *toto = 0 ;
00045    }
00046 }
00047 
00048 PsnSharedFreeStoreMemoryManager::~PsnSharedFreeStoreMemoryManager () {
00049    for (int i = 0 ; i < _queueSize ; i++ ) {
00050       assert (_tabTailleLibre [ i ] == _blockSize) ;
00051       delete _tabLibres [ i ] ;
00052    }
00053    delete [] _tabLibres ;
00054    delete [] _tabTailleLibre ;
00055 }
00056 
00057 
00058 size_t PsnSharedFreeStoreMemoryManager::getSize() {
00059    return _sizeDsm ;
00060 }
00061         
00062 void * PsnSharedFreeStoreMemoryManager::mallocAvecMemoire(size_t size, int frame) {
00063    int oldCurrentWritableIndex = _currentWritableIndex ;
00064    _currentWritableIndex = frame ;
00065    void * resul=PsnFramedMemoryManager::allocateSizeRemembered(size);
00066    _currentWritableIndex = oldCurrentWritableIndex ;
00067    return resul;
00068 }
00069 
00070 
00071 void * PsnSharedFreeStoreMemoryManager::mmalloc (size_t size) {
00072 
00073    void * resul ;
00074    size_t allocatedSize=alignedSize(size);
00075    //cerr<<"PsnSharedFreeStoreMemoryManager::mmalloc "<<allocatedSize<<" "<<_tabTailleLibre[ nextQueueIndex ]<<endl;
00076    if (allocatedSize <= _tabTailleLibre[ _currentWritableIndex ]) {
00077       resul = getFromThisFree( & (_tabLibres [ _currentWritableIndex ]) , allocatedSize) ;
00078       if ( resul != NULL ) {
00079          if ( _tabTailleLibre [ _currentWritableIndex ] == _blockSize ) {
00080             addBlockInSync( _currentWritableIndex ); 
00081          }
00082          _tabTailleLibre [ _currentWritableIndex ] -= allocatedSize ;
00083       }
00084    }
00085    else {
00086       resul = NULL ;
00087    }
00088    //cerr<<"Block alloué à : "<<resul<<", debut de la memoire gérée : "<<(void *)_startDsm<<", page relative "<<_currentWritableIndex<<endl;
00089    return resul ;
00090 }
00091                                   
00092 void PsnSharedFreeStoreMemoryManager::mfree (void * ptr , size_t size) {
00093    assert( inAdressSpace(ptr) ) ;
00094 
00095    size_t allocatedSize=alignedSize(size);
00096    //cerr<<"PsnSharedFreeStoreMemoryManager::mfree a "<<ptr<<" "<<allocatedSize<<endl;
00098    unsigned int offsetInMemory = globalAddressToLocal ( ptr ) ;
00099    unsigned int blockNumber = offsetInMemory / _blockSize ;
00100 
00101    //unsigned int offsetInBlock = offsetInMemory - blockNumber * _blockSize ;
00102 
00103    //assert ( offsetInBlock < _blockSize ) ;
00104    assert ( blockNumber < _queueSize ) ;
00105 
00107    addInThisFree( & _tabLibres [ blockNumber ] , offsetInMemory , allocatedSize ) ;
00108 
00110    _tabTailleLibre [ blockNumber ] -= allocatedSize ;
00111    
00113    if (_tabTailleLibre [ blockNumber ] == 0 ) {
00114       cerr<<"PsnSharedFreeStoreMemoryManager::mfree "<<blockNumber<<" removed from sync"<<endl;
00115       removeBlockFromSync ( blockNumber ) ;
00116    }
00117    
00118 }
00119 
00120 

logo OpenMask

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

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