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

PsnMomeWriterFifo.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 PsnMomeWriterFifoHEADER
00019 #define PsnMomeWriterFifoHEADER
00020 
00021 #include "PsnMomeFifo.h"
00022 
00025 template <typename Type>
00026 class PsnMomeWriterFifo : public PsnMomeFifo<Type>
00027 {
00028 public:
00029    PsnMomeWriterFifo(const int, PsnRelaxedMemoryManager * myMemory);
00030    PsnMomeWriterFifo(void * fifoAddress , const unsigned int size);
00031    virtual ~PsnMomeWriterFifo() ;
00032    virtual void set (const Type & val, const PsDate & date) ;
00033    virtual unsigned int getNumberOfPresentValues( int maxCherche = -1 ) const ;
00035    virtual void setInPlace ( const Type & val, const PsDate & date) ;
00036 
00038    virtual Type & getNextPlaceHolder() ;
00039    virtual void clear() ;
00040    virtual void printDebuggingInformation() const ;
00041 protected:
00043    virtual unsigned int findFirstValid() const ;
00044 
00046    virtual const PsDate & getOldestDateAfter(const int indice) const ;
00047 
00048 };
00049 
00050 
00051 template <typename Type> 
00052 PsnMomeWriterFifo<Type>::PsnMomeWriterFifo(const int size, PsnRelaxedMemoryManager * myMemory) : 
00053    PsnMomeFifo<Type> (size,myMemory) {
00054 
00055 }
00056 
00057 
00058 
00059 template <typename Type> 
00060 PsnMomeWriterFifo<Type>::PsnMomeWriterFifo(void * fifoAddress , const unsigned int size) : 
00061    PsnMomeFifo<Type> (fifoAddress,size) {
00062    
00063 }
00064 
00065 
00066 
00067 template <typename Type>
00068 PsnMomeWriterFifo<Type>::~PsnMomeWriterFifo() {
00069 
00070 }
00071 
00072 
00073 
00074 template <typename Type> 
00075 void PsnMomeWriterFifo<Type>::set(const Type & val, const PsDate & date) {
00076 #ifdef _DEBUGATTRIBUTSMOME
00077    cerr<<"PsnMomeWriterFifo<"<<typeid(Type).name()<<">::"<<this<<"::set("<<val<<", "<<date<<")"<<endl;
00078 #endif
00079    PsDate & oldDateAtWrittenIndex ((*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].dateValeur) ;
00080 //     cerr<<"Written at adress : "<<&(*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()]
00081 //         <<" which is page : "<<PsnSharedMemoryManager::whichSharedMemoryManager(_tab)->globalAddressToLocal(&(*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()])/4096+4096
00082 //         <<endl;
00083    (*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].valeur = val ;
00084    //assert (oldDateAtWrittenIndex != date) ;
00085    if ( oldDateAtWrittenIndex != date ) {//avoid rechanging 
00086       (*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].dateValeur = date ;
00087       _dateOfOldestValidValue = getOldestDateAfter (PsnRelaxedMemoryManager::getWritableQueueIndex()) ;
00088       _lastValidIndex = PsnRelaxedMemoryManager::getWritableQueueIndex() ;
00089       (*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].datePlusVieilleValeurValide = _dateOfOldestValidValue ;
00090 
00091    }
00092 #ifdef _DEBUGATTRIBUTSMOME
00093    cerr<<"PsnMomeWriterFifo<"<<typeid(Type).name()<<">::"<<this<<"::set done"<<endl;
00094 #endif
00095 }
00096 
00097 
00098 template <typename Type> 
00099 void PsnMomeWriterFifo<Type>::setInPlace(const Type & newValue, const PsDate & date) {
00100 
00101 
00102    PsDate & oldDateAtWrittenIndex ((*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].dateValeur) ;
00103 
00104    assert (&((*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].valeur) == &newValue ) ;
00105 
00106    if ( oldDateAtWrittenIndex != date ) //avoid rechanging 
00107       {
00108          (*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].dateValeur = date ;
00109          _dateOfOldestValidValue = getOldestDateAfter (PsnRelaxedMemoryManager::getWritableQueueIndex()) ;
00110          _lastValidIndex = PsnRelaxedMemoryManager::getWritableQueueIndex() ;
00111          (*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].datePlusVieilleValeurValide = _dateOfOldestValidValue ;
00112          
00113       }
00114 }
00115 
00116 template <typename Type>
00117 Type & PsnMomeWriterFifo<Type>::getNextPlaceHolder() 
00118 {
00119    return (*_tab)[PsnRelaxedMemoryManager::getWritableQueueIndex()].valeur ;
00120 }
00121 
00122 
00123 template <typename Type> 
00124 unsigned int PsnMomeWriterFifo<Type>::getNumberOfPresentValues( int maxCherche ) const {
00125 #ifdef _DEBUGATTRIBUTSMOME
00126    cerr<<"PsnMomeWriterFifo<"<<typeid(Type).name()<<">::"<<this<<"::getNumberOfPresentValues("<<maxCherche<<")"<<endl;
00127 #endif
00128    unsigned int nbATrouver ;
00129    if (maxCherche == -1) {
00130       nbATrouver = _fifoSize ;
00131    }
00132    else {
00133       nbATrouver = maxCherche ; 
00134    }
00135    int lookAt = findFirstValid () ;
00136 
00137    unsigned int nbValidFound = 0 ;
00138    unsigned int nbLookedAt = 0 ;
00139 
00140    while ( ( nbValidFound < nbATrouver ) && 
00141            ( nbLookedAt < _fifoSize ) ) {
00142          if ( (*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) nbValidFound++ ;
00143          nbLookedAt++ ;
00144          if (lookAt != 0 ) {
00145             lookAt--;
00146          }
00147          else {
00148             lookAt = _fifoSize -1 ;
00149          }      
00150    } 
00151    return nbValidFound ;
00152 }
00153 
00154 
00155 
00156 template <typename Type> 
00157 const PsDate & PsnMomeWriterFifo<Type>::getOldestDateAfter (int i) const {
00158    //if the assertion isn't valid, the loop might never end
00159    assert ((*_tab)[i].dateValeur >= _dateOfOldestValidValue ) ;
00160 
00161    int lookAt = ( i + 1 ) % _fifoSize ;
00162    int nbValidFound = 0 ;
00163    
00164    if ((*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) nbValidFound++ ;
00165 
00166    while (nbValidFound != 1) {
00167       lookAt = ( lookAt + 1 ) % _fifoSize ;
00168       if ((*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) nbValidFound++ ;
00169    }
00170 
00171    return (*_tab) [lookAt].dateValeur ;
00172 }
00173 
00174 
00175 
00176 template <typename Type>
00177 unsigned int PsnMomeWriterFifo<Type>::findFirstValid() const {
00178 #ifdef _DEBUGATTRIBUTSMOME
00179    cerr<<"PsnMomeWriterFifo<"<<typeid(Type).name()<<">::"<<this<<"::findFirstValid ()"<<endl;
00180 #endif
00181    return _lastValidIndex ;
00182 }
00183 
00184 
00185 
00186 template <typename Type>
00187 void PsnMomeWriterFifo<Type>::clear() {
00188    _dateOfOldestValidValue = (*_tab)[_lastValidIndex].dateValeur ;
00189    (*_tab)[_lastValidIndex].dateValeur -- ;
00190 }
00191 
00192 
00193 
00194 template <typename Type>
00195 void PsnMomeWriterFifo<Type>::printDebuggingInformation() const {
00196    cerr<<" PsnMomeWriterFifo<"<<typeid(Type).name()<<">::"<<this<<"::printDebuggingInformation () "<<endl;
00197    PsnMomeFifo<Type>::printDebuggingInformation() ;
00198 }
00199 
00200 #endif
00201 
00202 
00203 
00204 

logo OpenMask

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

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