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

PsnMomeArray.h

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 #ifndef PsnMomeArrayHEADER
00019 #define PsnMomeArrayHEADER
00020 
00021 #include "PsnArray.h"
00022 
00023 class PsnRelaxedMemoryManager ;
00024 
00027 template <typename T>
00028 class PsnMomeArray : public PsnAbstractArray< T > {
00029 public: 
00030    PsnMomeArray ( size_t taille, PsnRelaxedMemoryManager & memoryManager );
00031    virtual ~PsnMomeArray () ;
00032    virtual T & operator [] ( int i ) ;
00033    virtual const T & operator [] ( int i ) const ;
00034    void * operator new(size_t size, PsnRelaxedMemoryManager * memoryManager );
00035    void operator delete(void*, size_t);
00036    virtual void resync ( PsnRelaxedMemoryManager * myMemory ) const ;
00037 protected:
00038    unsigned int _offset ;
00039    size_t _step ;
00040    size_t _taille ;
00041 };
00042 
00043 #include "PsnRelaxedMemoryManager.h"
00044 
00045 template <typename T>
00046 void * PsnMomeArray< T >::operator new(size_t size, PsnRelaxedMemoryManager * memoryManager ) {
00047    return memoryManager->mmallocForOnce (size) ;
00048 }
00049 
00050 template <typename T>
00051 void PsnMomeArray< T >::operator delete(void* addr, size_t size) {
00052    PsnRelaxedMemoryManager * freeFrom = dynamic_cast <PsnRelaxedMemoryManager * > (PsnMemoryManager::whichMemoryManager( addr )) ;
00053    //assert (freeFrom != NULL) ;
00054    freeFrom->mfreeForOnce(addr, size) ;
00055   
00056 }
00057 
00058 
00059 template <typename T>
00060 PsnMomeArray< T >::PsnMomeArray(size_t taille, PsnRelaxedMemoryManager & memoryManager) : PsnAbstractArray<T> (taille), _taille(taille) {
00061    HeapStackTop specialContext(&memoryManager);
00062   //cerr<<"PsnMomeArray< T >::PsnMomeArray "<<sizeof(T)<<" "<<_taille<<endl;
00063    unsigned int initialOffset;   
00064    _offset=(unsigned int)memoryManager.mmallocInPages(sizeof(T), &initialOffset, &_step);
00065    assert( pthread_getspecific(HeapStackTop::globalMemoryManagerKey) != NULL );
00066    for (unsigned int i=0; i<taille ; i++) {
00067       memoryManager.anticipateFreeStoreAllocation(i);
00068       T * tmp = new((void *) (_offset + i *_step) ) T();
00069       tmp->dateValeur = PsDate( - 2 ) ;
00070    }
00071    memoryManager.anticipateFreeStoreAllocation(-1);
00072 }
00073 
00074 template <typename T>
00075 PsnMomeArray< T >::~PsnMomeArray() {
00076    PsnRelaxedMemoryManager * memoryManager = dynamic_cast<PsnRelaxedMemoryManager *>(PsnMemoryManager::whichMemoryManager((void *)_offset));
00077    //assert (memoryManager != NULL) ;
00078    memoryManager->mfreeInPages((void *)(_offset), sizeof(T));
00079 }
00080 
00081 
00082 template <typename T>
00083 T & PsnMomeArray< T >::operator [] ( int i ) {
00084    //cerr<<"PsnMomeArray< T >::operator [] "<<(void *)_offset<<" "<< i <<" "<<_taille<<endl;
00085    //assert(i < _taille) ;
00086    return *((T *) (_offset + i * _step)) ;
00087 }
00088 
00089 
00090 template <typename T>
00091 const T & PsnMomeArray< T >::operator [] ( int i ) const {
00092    //assert(i < _taille) ;
00093    return *(T *) (_offset + i * _step) ;
00094 }
00095 template <typename T>
00096 void PsnMomeArray< T >::resync ( PsnRelaxedMemoryManager * myMemory ) const {
00097    myMemory->strongSynchronizeRegion( (myMemory->globalAddressToLocal((void *)_offset)/4096) * 4096,
00098                                        _step * _taille);
00099 }
00100 #endif

logo OpenMask

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

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