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

PsnOutputOffsetTable.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 #if defined (_MOME) && !defined (_OLDALLOCATORS)
00019 #include <PsnOutputOffsetTable.h>
00020 #include <PsnSharedMemoryManager.h>
00021 #include <PsnLock.h>
00022 #include <PsNomSym.h>
00023 #include <PsNomSymServer.h>
00024 #include <unistd.h>
00025 
00026 PsnOutputOffsetTable::PsnOutputOffsetTable() {
00031    PsnLock toto;
00032    _myLockNumber=toto.getLock();
00033    _locked=false;
00034 }
00035 
00036 void PsnOutputOffsetTable::lock() {
00037 #ifdef _DEBUGLOCK
00038    cerr<<"PsnOutputOffsetTable::lock("<<(int)_myLockNumber<<")";
00039    cerr.flush() ;
00040    //if (MomeNumberOfProcessors > 2 ) sleep(1);
00041 #endif
00042    MomeMutexLock(_myLockNumber);
00043    assert(!_locked);
00044    _locked=true;
00045    _lockedBy=MomeMe;
00046 #ifdef _DEBUGLOCK
00047    cerr<<" obtenu"<<endl;
00048 #endif
00049 }
00050 
00051 void PsnOutputOffsetTable::unlock() {
00052 #ifdef _DEBUGLOCK
00053    cerr<<"PsnOutputOffsetTable::lock("<<(int)_myLockNumber<<")";
00054    cerr.flush();
00055 #endif
00056    assert(_lockedBy==MomeMe);
00057    _locked=false;
00058    MomeMutexUnLock(_myLockNumber);
00059 #ifdef _DEBUGLOCK
00060    cerr<<" relache"<<endl;
00061 #endif
00062 }
00063 
00064 void * PsnOutputOffsetTable::operator new(size_t size) {
00065    PsnControleurMome::STLSharedMemoryManager->lockIfNeeded();
00066    void * resul(PsnControleurMome::STLSharedMemoryManager->mmalloc(size));
00067    PsnControleurMome::STLSharedMemoryManager->unlockIfNeeded();
00068    return resul;
00069 }
00070 
00071 void PsnOutputOffsetTable::operator delete(void * ptr,size_t size) {
00072    PsnControleurMome::STLSharedMemoryManager->lockIfNeeded();
00073 #ifdef _DEBUGMFREE
00074    cerr<<"PsnOutputOffsetTable::operator delete : appel de mfree ";
00075 #endif
00076    PsnControleurMome::STLSharedMemoryManager->mfree(ptr,size);
00077 #ifdef _DEBUGMFREE
00078    cerr<<"done"<<endl;
00079 #endif
00080    PsnControleurMome::STLSharedMemoryManager->unlockIfNeeded();
00081 }
00082 
00083 void PsnOutputOffsetTable::declareOutput(const PsNomSym & object, const PsNomSym & name, unsigned long offset) {
00084    // cerr<<"PsnOutputOffsetTable::declareOutput"<<endl;
00085    assert(_locked);
00086    iterator i=find(object._identifiant);
00087    if (i==end()) {
00088       pair <iterator,bool> res = insert(value_type(object._identifiant,internalHash_map()));
00089       i=res.first;
00090    }
00091    (*i).second.insert(internalHash_map::value_type(name._identifiant,offset));
00092 #ifdef _DEBUGOUTPUTOFFSETTABLE
00093 //     PsNomSym::serveurDeNom->lock();
00094 //     for (i=begin();i!=end();i++)
00095 //        {
00096 //       cerr<<PsNomSym::serveurDeNom->Chaine((*i).first)<<" : "<<endl;
00097 //       for (internalHash_mapIterator j=(*i).second.begin();
00098 //            j!=(*i).second.end();j++) {
00099 //          cerr<<"     "<<PsNomSym::serveurDeNom->Chaine((*j).first)<<" : "<<(*j).second<<endl;
00100 //       }
00101 //        }
00102 //     PsNomSym::serveurDeNom->unlock();
00103    //cerr<<"PsnOutputOffsetTable::declareOutput fin"<<endl;
00104 #endif
00105 }
00106  
00107 void PsnOutputOffsetTable::invalidateOutput(const PsNomSym & object, const PsNomSym & name) {
00108    assert(_locked);
00109    iterator i=find(object._identifiant);
00110    if (i != end()) {
00111       (*i).second.erase(name._identifiant);
00112       if ((*i).second.empty()) erase(object._identifiant) ;
00113    }
00114    else {
00115       cerr<<"Les sorties (dont "
00116           <<name
00117           <<" ) de l'objet de simulation "
00118           <<object
00119           <<" ne sont pas dans la table"
00120           <<" dans la méthode ";
00121       //PsnControleur::error("PsnOutputOffsetTable::invalidateOutput");
00122    }
00123 }
00124 
00125 pair<bool,unsigned int> PsnOutputOffsetTable::getOutputOffset(const PsNomSym & object, const PsNomSym & name) {
00126    //cerr<<"PsnOutputOffsetTable::getOutputOffset"<<endl;
00127    pair<bool, unsigned int> resul;
00128    iterator i=find(object._identifiant);
00129    if (i!=end()) {
00130       internalHash_mapIterator j = (*i).second.find(name._identifiant); 
00131       if (j!=(*i).second.end()) {
00132          resul.first = true ;
00133          resul.second = (*j).second ;
00134       }
00135       else {
00136          resul.first = false ;
00137       }
00138    }
00139    else {
00140       resul.first = false ;
00141    }
00142 #ifdef _DEBUGOUTPUTOFFSETTABLE
00143    cerr<<object<<","<<name<<" : "<<resul.second<<endl;
00144 #endif
00145    //cerr<<"PsnOutputOffsetTable::getOutputOffset fin"<<endl;
00146    return resul;
00147 }
00148 #endif

logo OpenMask

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

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