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 <PsnBroadcastManager.h> 00020 #include <PsnSharedMemoryManager.h> 00021 #include <PsName.h> 00022 #include <PsnNew.h> 00023 #include <PsnLock.h> 00024 #include <PsnUniqueCreator.h> 00025 #include <PsDistributedController.h> 00026 #include <unistd.h> 00027 00028 const int PsnBroadcastManager::nbTablesDansBuffer=3; 00029 00030 PsnBroadcastManager::PsnBroadcastManager(PsnUniqueCreator & aCreator) : 00031 _allProcessesId("_allProcesses"), 00032 _mirrorToReferentialId("_MirrorId") 00033 { 00034 PsnLock toto; 00035 _myLockNumber=toto.getLock(); 00036 #ifdef _DEBUGLOCK 00037 cerr<<"PsnBroadcastManager::PsnBroadcastManager : le processeur " 00038 <<MomeMe 00039 <<" a obtenu le numero de verrou "<<(int)_myLockNumber<<endl; 00040 #endif 00041 for (int i=0; i<nbTablesDansBuffer ; i++) { 00042 broadcastedEventsTable[i]=aCreator.newbroadcastManagerTable(i); 00043 assert ( PsnSharedMemoryManager::whichSharedMemoryManager(broadcastedEventsTable[i]) != NULL ) ; 00044 } 00045 _memoryManagerOfmyData=PsnSharedMemoryManager::whichSharedMemoryManager(broadcastedEventsTable[0]); 00046 cerr<<broadcastedEventsTable<<endl; 00047 assert ( _memoryManagerOfmyData != NULL ) ; 00048 assert ( PsnSharedMemoryManager::whichSharedMemoryManager( this ) == NULL ); 00049 _locked=false; 00050 _currentWritableTable=0; 00051 _currentReadableTable=1; 00052 _currentDeletableTable=2; 00053 //lancer le thread de destruction des événements et des messages 00054 } 00055 00056 PsnBroadcastManager::~PsnBroadcastManager() { 00057 00058 } 00059 00060 void PsnBroadcastManager::sendEvent(const PsName & receiverProcess, unsigned int offsetOfEvent) { 00061 //install in this scope our memoryManager as the default memory manager 00062 HeapStackTop toto(_memoryManagerOfmyData); 00063 //Send the event to the appropriate controler 00064 lock(); 00065 broadcastedEventsTable[_currentWritableTable]->insert(broadcastedEventsTable[_currentWritableTable]->begin(),_myPairType(receiverProcess,offsetOfEvent)); 00066 unlock(); 00067 } 00068 00069 void PsnBroadcastManager::broadcastEvent(unsigned int offsetOfEvent) { 00070 //install in this scope our memoryManager as the default memory manager 00071 HeapStackTop toto(_memoryManagerOfmyData); 00072 //Send the event to the appropriate controler 00073 lock(); 00074 broadcastedEventsTable[_currentWritableTable]->insert(broadcastedEventsTable[_currentWritableTable]->begin(),_myPairType(_allProcessesId,offsetOfEvent)); 00075 unlock(); 00076 } 00077 00078 00079 void PsnBroadcastManager::addToEventList(PsList<PsEvent *> * anEventList, const PsName & aProcess) { 00080 _myTypeOfTable::iterator i; 00081 for(i=broadcastedEventsTable[_currentReadableTable]->begin(); 00082 i!=broadcastedEventsTable[_currentReadableTable]->end(); 00083 i++) 00084 { 00085 if ((*i).first==aProcess 00086 ||(*i).first==_allProcessesId) 00087 { 00088 PsEvent::insertInList(anEventList, 00089 ((PsEvent *)_memoryManagerOfmyData->localAddressToGlobal((*i).second))); 00090 } 00091 } 00092 } 00093 00094 void PsnBroadcastManager::dispatchEventsOfList(PsDistributedController & theLocalControler) { 00095 #ifdef _DEBUGEVT 00096 cerr<<"PsnBroadcastManager::dispatchEventsOfList for "<<theLocalControler.getObjectDescriptor()->Processus()<<endl; 00097 #endif 00098 _myTypeOfTable::iterator i; 00099 const PsName & aProcess(theLocalControler.getObjectDescriptor().getProcess()); 00100 00101 #ifdef _DEBUGEVT 00102 cerr<<"PsnBroadcastManager::dispatchEventsOfList : broadcastedEventsTable["<<_currentReadableTable<<"] : "<<broadcastedEventsTable[_currentReadableTable]->size()<<" event(s) present(s)"<<endl; 00103 #endif 00104 00105 for(i=broadcastedEventsTable[_currentReadableTable]->begin(); 00106 i!=broadcastedEventsTable[_currentReadableTable]->end(); 00107 i++) 00108 { 00109 #ifdef _DEBUGEVT 00110 cerr<<(*i).first<<endl; 00111 cerr<<(*i).second<<endl; 00112 cerr<<_memoryManagerOfmyData<<endl; 00113 cerr<<_memoryManagerOfmyData->localAddressToGlobal((*i).second)<<endl; 00114 cerr<<(PsEvent *)_memoryManagerOfmyData->localAddressToGlobal((*i).second)<<endl; 00115 cerr<<*(PsEvent *)_memoryManagerOfmyData->localAddressToGlobal((*i).second)<<endl; 00116 #endif 00117 if ((*i).first==aProcess 00118 ||(*i).first==_allProcessesId) 00119 { 00120 theLocalControler.dispatchEvent((PsEvent *)_memoryManagerOfmyData->localAddressToGlobal((*i).second)); 00121 } 00122 } 00123 #ifdef _DEBUGEVT 00124 cerr<<"PsnBroadcastManager::dispatchEventsOfList fin"<<endl; 00125 #endif 00126 } 00127 00128 00129 void PsnBroadcastManager::sync() { 00130 int temp; 00131 //the _current*Table variables are kept coherant accros the cluster because of the barrier at each simulation step 00132 #ifdef _DEBUGEVT 00133 cerr<<"PsnBroadcastManager::sync()"<<endl; 00134 #endif 00135 temp=_currentReadableTable; 00136 _currentReadableTable=_currentWritableTable; 00137 _currentWritableTable=_currentDeletableTable; 00138 _currentDeletableTable=temp; 00139 //La currentReadeableTable a du être lu : il faut donc la détruire 00140 if (MomeMe==0) { 00141 _myTypeOfTable::iterator i,needsDelete; 00142 i=broadcastedEventsTable[_currentDeletableTable]->begin(); 00143 while( i!=broadcastedEventsTable[_currentDeletableTable]->end() ) 00144 { 00145 needsDelete=i; 00146 i++; 00147 broadcastedEventsTable[_currentDeletableTable]->erase( needsDelete ); 00148 } 00149 } 00150 //cerr<<"PsnBroadcastManager::sync() fin"<<endl; 00151 } 00152 void PsnBroadcastManager::lock() { 00153 #ifdef _DEBUGLOCK 00154 cerr<<"PsnBroadcastManager::lock("<<(int)_myLockNumber<<","<<&_accessToLock<<")"; 00155 cerr.flush() ; 00156 sleep (1) ; 00157 #endif 00158 _accessToLock.protect () ; 00159 assert(!_locked); 00160 MomeMutexLock(_myLockNumber); 00161 _locked=true; 00162 #ifdef _DEBUGLOCK 00163 cerr<<" obtenu"<<endl; 00164 #endif 00165 } 00166 ; 00167 00168 void PsnBroadcastManager::unlock() { 00169 #ifdef _DEBUGLOCK 00170 cerr<<"PsnBroadcastManager::lock("<<(int)_myLockNumber<<","<<&_accessToLock<<")"; 00171 cerr.flush() ; 00172 //sleep (1) ; 00173 #endif 00174 assert(_locked); 00175 _locked=false; 00176 MomeMutexUnLock(_myLockNumber); 00177 #ifdef _DEBUGLOCK 00178 cerr<<" relache"<<endl; 00179 #endif 00180 _accessToLock.unprotect () ; 00181 } 00182 00183 const PsName & PsnBroadcastManager::getMirrorToReferentialId() { 00184 return _mirrorToReferentialId; 00185 } 00186 00187 const PsName & PsnBroadcastManager::getAllProcessesId() { 00188 return _allProcessesId; 00189 } 00190 00191 #endif 00192 00193 00194 00195 00196 00197
| Documentation generated on Mon Nov 25 15:25:00 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |