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

PsnMomeFifo.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 PsnMomeFifoHEADER
00019 #define PsnMomeFifoHEADER
00020 
00021 
00022 class PsnSharedMemoryManager;
00023 
00024 #include <PsnAbstractFifo.h>
00025 #include <typeinfo>
00026 #include <PsnArray.h>
00027 #include <PsnNew.h>
00028 #include "PsnMutexLock.h"
00029 
00030 
00031 #ifdef _SGI
00032 #include <new.h>
00033 #include <malloc.h>
00034 #else
00035 #include <new>
00036 #endif
00037 
00040 template <typename Type>
00041 class PsnMomeFifo : public PsnAbstractFifo<Type>
00042 {
00043 public:
00044    PsnMomeFifo(const unsigned int, PsnRelaxedMemoryManager * myMemory);
00045    PsnMomeFifo(void * fifoAddress,  const unsigned int);
00046    virtual ~PsnMomeFifo() ;
00047    virtual void set (const Type & val, const PsDate & date) = 0 ;
00048    virtual unsigned int getNumberOfPresentValues( int maxCherche = -1 ) const = 0;
00049    virtual const Type & getPreceedingValue (const unsigned int indice) const ;
00050    virtual const PsDate & getPreceedingDate(const unsigned int indice) const ;
00051 
00053    virtual void setInPlace ( const Type & val, const PsDate & date) = 0 ;
00054 
00056    virtual Type & getNextPlaceHolder() = 0 ;
00057 
00058    virtual void clear() = 0 ;
00059    virtual void printDebuggingInformation() const = 0;
00060    void * fifo() ;
00061    virtual void resyncFifo ( PsnRelaxedMemoryManager * myMemory ) const ;
00062 //     virtual void initialiseContext() const ; 
00063 //     virtual unsigned int getNumberOfPresentValuesUsingContext( int maxCherche = -1 ) const ;
00064 //     virtual const Type & getPreceedingValueUsingContext (const int indice) const ;
00065 //     virtual const PsDate & getPreceedingDateUsingContext (const int indice) const ;
00066 
00067 protected:
00068    virtual unsigned int findFirstValid() const = 0 ;
00069 
00071    class valeurDate {
00072    public:
00073       void * operator new(size_t size, void * place) {
00074          return place ;
00075       }
00076       PsDate dateValeur;
00077       Type   valeur ;    
00078       PsDate datePlusVieilleValeurValide ; 
00079    };
00080    
00082    PsnAbstractArray <valeurDate> * _tab ;
00083 
00085    mutable PsDate _dateOfOldestValidValue ; 
00086    mutable unsigned int _lastValidIndex ;
00087 
00089    mutable unsigned int _offsetToMostRecentOfLastExamined ;
00091    mutable unsigned int _indexOfLastValueExamined ;
00093    mutable PsnMutexLock _accessToContext ;
00094 
00095 };
00096 
00097 #include <PsnMomeReaderFifo.h>
00098 #include <PsnMomeWriterFifo.h>
00099 
00100 
00101 template <typename Type> 
00102 void PsnMomeFifo<Type>::printDebuggingInformation() const {
00103    PsnAbstractFifo<Type>::printDebuggingInformation() ;
00104    cerr<<"Valeur du tableau : "<<endl;
00105    _tab->printDebuggingInformation (_fifoSize) ;
00106    cerr<<"_dateOfOldestValidValue : "<<_dateOfOldestValidValue<<endl;
00107    cerr<<"_lastValidIndex : "<<_lastValidIndex<<endl;
00108 }
00109 
00110 
00111 template <typename Type> 
00112 void * PsnMomeFifo<Type>::fifo() {
00113    return (void *)_tab ;
00114 }
00115 
00116 template <typename Type> 
00117 const Type & PsnMomeFifo<Type>::getPreceedingValue (const unsigned int offsetToMostRecent) const {
00118 #ifdef _DEBUGATTRIBUTSMOME
00119    cerr<<"PsnMomeFifo<"<<typeid(Type).name()<<">::"<<this<<"::getPreceedingValue ("<<offsetToMostRecent<<") const"<<endl;
00120 #endif
00121 
00122    assert (offsetToMostRecent >= 0) ;
00123    assert (offsetToMostRecent < _fifoSize - 2 ) ;
00124 
00125    int lookAt = findFirstValid () ;
00126 #ifdef _DEBUGATTRIBUTSMOME
00127    cerr<<"First valid is : "<<lookAt<<endl;
00128    printDebuggingInformation() ;
00129 #endif
00130 
00131    unsigned int offsetToMostRecentOfLastFound = -1 ;
00132 
00133    if ( (*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) offsetToMostRecentOfLastFound++ ;
00134 
00135    while ( offsetToMostRecentOfLastFound != offsetToMostRecent ) {
00136       if ( lookAt != 0 ) {
00137          lookAt--;
00138       }
00139       else {
00140          lookAt = _fifoSize - 1 ;
00141       }
00142       
00143       if ( (*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) offsetToMostRecentOfLastFound++ ;
00144    }
00145 
00146    return (*_tab)[lookAt].valeur ;
00147 }
00148 
00149 
00150 template <typename Type> 
00151 void PsnMomeFifo<Type>::resyncFifo( PsnRelaxedMemoryManager * myMemory ) const {
00152    ((PsnMomeArray<valeurDate> *) _tab )->resync( myMemory ) ;
00153 }
00154 
00155 
00156 
00157 
00158 template <typename Type> 
00159 const PsDate & PsnMomeFifo<Type>::getPreceedingDate (const unsigned int offsetToMostRecent) const {
00160 #ifdef _DEBUGATTRIBUTSMOME
00161    cerr<<"PsnMomeFifo<"<<typeid(Type).name()<<">::"<<this<<"::getPreceedingDate ("<<offsetToMostRecent<<") const"<<endl;
00162    printDebuggingInformation();
00163 #endif
00164 
00165    assert (offsetToMostRecent >= 0) ;
00166 
00167    if (offsetToMostRecent > 4) cerr<<"C'est anormal de demander ŕ "<<offsetToMostRecent<<endl;
00168    assert (offsetToMostRecent < _fifoSize - 2) ;
00169 
00170    int lookAt = findFirstValid () ;
00171    unsigned int offsetToMostRecentOfLastExamined = -1 ;
00172 
00173    if ( (*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) offsetToMostRecentOfLastExamined++ ;
00174 
00175    
00176    while ( offsetToMostRecentOfLastExamined != offsetToMostRecent ) {
00177       if ( lookAt != 0 ) {
00178          lookAt--;
00179       }
00180       else {
00181          lookAt = _fifoSize - 1 ;
00182       }
00183       
00184       if ( (*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) offsetToMostRecentOfLastExamined++ ;
00185    }
00186 
00187    return (*_tab)[lookAt].dateValeur ;
00188 }
00189 
00190 template <typename Type> 
00191 PsnMomeFifo<Type>::~PsnMomeFifo () {
00192 #ifdef _DEBUGEXEC
00193    cerr<<"PsnMomeFifo<Type>::~PsnMomeFifo ()"<<endl;
00194 #endif
00195 }
00196 
00197 template <typename Type> 
00198 PsnMomeFifo<Type>::PsnMomeFifo (const unsigned int taille, PsnRelaxedMemoryManager * myMemory) : PsnAbstractFifo<Type>(taille), _offsetToMostRecentOfLastExamined(taille) {
00199    
00200    myMemory->lockIfNeeded ( ) ;
00201    
00202    _tab = new(myMemory) PsnMomeArray< valeurDate > ( taille, *myMemory) ;
00203    
00204    myMemory->unlockIfNeeded ( ) ;
00205 
00206    _dateOfOldestValidValue = PsDate ( -1 ); 
00207    _lastValidIndex = ( PsnRelaxedMemoryManager::getReadableQueueIndex() - 1 + _fifoSize ) % _fifoSize ;
00208 }
00209 
00210 
00211 
00212 template <typename Type> 
00213 PsnMomeFifo<Type>::PsnMomeFifo (void * fifoAddress, const unsigned int taille)
00214    : PsnAbstractFifo<Type>(taille), 
00215    _offsetToMostRecentOfLastExamined(taille) {
00216    
00217    _tab =  (PsnMomeArray< valeurDate > * ) fifoAddress ;
00218    
00219    _dateOfOldestValidValue = PsDate ( -1 ); 
00220 
00221    _lastValidIndex = ( PsnRelaxedMemoryManager::getReadableQueueIndex() - 1 + _fifoSize ) % _fifoSize ;
00222 }
00223 
00224 
00225 #endif
00226 
00227 

logo OpenMask

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

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