From 323290ec30a1e577a552f2ab5f8a3b2065c4f3f4 Mon Sep 17 00:00:00 2001 From: buret Date: Fri, 7 Sep 2007 12:52:06 +0000 Subject: Maximus simulator: modify 'getNextElement' => Before this modification, Maximus used to: 1) Check that all stations are IDLE; if not, process messages read from pipe until all stations are IDLE. 2) If there is no more event to process at the current tick, update current tick to the next tick where there are events to process. 3) Process all the events to send at current tick. 4) Remove all processed events from the network clock event list, i.e. all events of the current tick. 4) Process messages read from pipe. 5) and so on... => After this modification, points number 3) and 4) has been modified: 3) Process ONE event to send at current tick, even if there are other events to process at the same tick (they will be processed on the next loop). 4) Remove the processed event from the network clock event list. Fixes #7. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@679 017c9cb6-072f-447c-8318-d5b54f68fe89 --- maximus/networkclock/src/NetworkClockEvtList.cpp | 62 ++++++++-------------- .../networkclock/src/NetworkClockEvtListTest.cpp | 36 +++++++------ maximus/networkclock/src/NetworkClockProcessor.cpp | 34 +++++------- 3 files changed, 56 insertions(+), 76 deletions(-) (limited to 'maximus/networkclock') diff --git a/maximus/networkclock/src/NetworkClockEvtList.cpp b/maximus/networkclock/src/NetworkClockEvtList.cpp index 6fc369d6ef..6630b97791 100644 --- a/maximus/networkclock/src/NetworkClockEvtList.cpp +++ b/maximus/networkclock/src/NetworkClockEvtList.cpp @@ -152,58 +152,40 @@ bool NetworkClockEvtList::addElement ( const NetworkClockEvt & evt_to_add ) // Return true while there are events to process at current tick, else return false +// Return true if there is an event to process in the network clock event list +// Return false if the network clock event list is empty // bool NetworkClockEvtList::getNextElement ( Network_Clock_Tick & tick_value, NetworkClockEvt & next_evt_to_process ) { logFunction(); - static Network_Clock_Tick currentTickValue = -1LL; - static EvtsList::const_iterator evtIterator; - static pair evtsToProcess; + static EvtsList::iterator evtIterator; bool bGet = false; - + if (!mListOfEvts.empty()) { - if ((Network_Clock_Tick)-1LL == currentTickValue) - { - if (0 != mListOfEvts.count(tick_value)) - { - /* Finds an element whose key is tick_value. */ - evtIterator = mListOfEvts.find (tick_value); - } - else - { - /* Finds the first element whose key strictly greater than tick_value. */ - evtIterator = mListOfEvts.upper_bound (tick_value); - } - - // update local current tick value - currentTickValue = evtIterator->first; - } - - /* Finds a range containing all elements whose key is currentTickValue. */ - evtsToProcess = mListOfEvts.equal_range(currentTickValue); - - if (evtIterator != evtsToProcess.second) - { - // set tick value to return - tick_value = currentTickValue; - - // find next event to process - next_evt_to_process = NetworkClockEvt(evtIterator->second); - - ++evtIterator; - bGet = true; + if (0 != mListOfEvts.count(tick_value)) + { + /* Finds an element whose key is tick_value. */ + evtIterator = mListOfEvts.find (tick_value); } else { - // clear processed events - mListOfEvts.erase(currentTickValue); - - // reset local current tick value - currentTickValue = -1LL; + /* Finds the first element whose key strictly greater than tick_value. */ + evtIterator = mListOfEvts.upper_bound (tick_value); } + + // update current tick value + tick_value = evtIterator->first; + + // set next event to process + next_evt_to_process = NetworkClockEvt(evtIterator->second); + + // clear event that will be processed + mListOfEvts.erase(evtIterator); + + bGet = true; } - + return bGet; } diff --git a/maximus/networkclock/src/NetworkClockEvtListTest.cpp b/maximus/networkclock/src/NetworkClockEvtListTest.cpp index 2f7561506d..bb8444fa9f 100644 --- a/maximus/networkclock/src/NetworkClockEvtListTest.cpp +++ b/maximus/networkclock/src/NetworkClockEvtListTest.cpp @@ -135,6 +135,12 @@ void NetworkClockEvtListTest::getNextElementTest (void) { logTest(); + Network_Clock_Tick tickValue = 0; + NetworkClockEvt evt (0, NETWORK_CLOCK_TYPE_STATION, 0); + + CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", + !mpNetworkClockEvtList->getNextElement (tickValue, evt) ); + // Insert Event 1 // NetworkClockEvt evt1; @@ -142,53 +148,51 @@ void NetworkClockEvtListTest::getNextElementTest (void) CPPUNIT_ASSERT_MESSAGE ( "insertElement failed", mpNetworkClockEvtList->insertElement (0, evt1) ); - + // Insert Event 2 // NetworkClockEvt evt2; evt2.setNetworkClockId(2); mpNetworkClockEvtList->insertElement (3524, evt2); - + // Insert Event 3 // NetworkClockEvt evt3; evt3.setNetworkClockId(3); mpNetworkClockEvtList->insertElement (6457, evt3); - + // Insert Event 4 // NetworkClockEvt evt4; evt4.setNetworkClockId(4); mpNetworkClockEvtList->insertElement (111, evt4); - mpNetworkClockEvtList->displayListOfEvts(); + // Insert Event 5 + // + NetworkClockEvt evt5; + evt5.setNetworkClockId(5); + mpNetworkClockEvtList->insertElement (111, evt5); - Network_Clock_Tick tickValue = 0; - NetworkClockEvt evt (0, NETWORK_CLOCK_TYPE_STATION, 0); + mpNetworkClockEvtList->displayListOfEvts(); CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", - (mpNetworkClockEvtList->getNextElement (tickValue, evt)) + mpNetworkClockEvtList->getNextElement (tickValue, evt) && (evt1 == evt) ); - CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", - !mpNetworkClockEvtList->getNextElement (tickValue, evt) ); - CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", (mpNetworkClockEvtList->getNextElement (tickValue, evt)) && (evt4 == evt) ); - CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", - !mpNetworkClockEvtList->getNextElement (tickValue, evt) ); - CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", (mpNetworkClockEvtList->getNextElement (tickValue, evt)) - && (evt2 == evt) ); + && (evt5 == evt) ); CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", - !mpNetworkClockEvtList->getNextElement (tickValue, evt) ); + mpNetworkClockEvtList->getNextElement (tickValue, evt) + && (evt2 == evt) ); CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", - (mpNetworkClockEvtList->getNextElement (tickValue, evt)) + mpNetworkClockEvtList->getNextElement (tickValue, evt) && (evt3 == evt) ); CPPUNIT_ASSERT_MESSAGE ( "getNextElement failed", diff --git a/maximus/networkclock/src/NetworkClockProcessor.cpp b/maximus/networkclock/src/NetworkClockProcessor.cpp index 1b7d035008..b2ce10f10a 100644 --- a/maximus/networkclock/src/NetworkClockProcessor.cpp +++ b/maximus/networkclock/src/NetworkClockProcessor.cpp @@ -230,28 +230,22 @@ bool NetworkClockProcessor::processNextEvt ( const Network_Clock_Tick max_tick_v { NetworkClockEvt evtToProcess; Network_Clock_Tick currentTickValue = getCurrentTickValue(); - bool bGetNext = true; - while (bGetNext) + + // If an event has been get, update tick and process evt + // + if (mpNetworkClockEvtList->getNextElement(currentTickValue, evtToProcess)) { - bGetNext = mpNetworkClockEvtList->getNextElement (currentTickValue, evtToProcess); - - // If an event has been get, update tick and process evt - // - if (bGetNext) + if ( (0 == max_tick_value) || (max_tick_value > currentTickValue) ) + { + bProcess = setCurrentTickValue(currentTickValue); + clog << logger(LOG_INFO) << "processing event at tick " << dec << getCurrentTickValue() << "..." << endl; + bProcess &= callMemberFunction (*this, arrayProcess[evtToProcess.getNetworkClockType()]) (evtToProcess); + } + else { - if ( (0 == max_tick_value) || (max_tick_value > currentTickValue) ) - { - bProcess = setCurrentTickValue(currentTickValue); - clog << logger(LOG_INFO) << "processing event at tick " << dec << getCurrentTickValue() << "..." << endl; - bProcess &= callMemberFunction (*this, arrayProcess[evtToProcess.getNetworkClockType()]) (evtToProcess); - } - else - { - setCurrentTickValue(max_tick_value); - clog << logger(LOG_INFO) << "tick " << dec << getCurrentTickValue() << " is reached" << endl; - bGetNext = false; - bProcess = false; - } + setCurrentTickValue(max_tick_value); + clog << logger(LOG_INFO) << "tick " << dec << getCurrentTickValue() << " is reached" << endl; + bProcess = false; } } } -- cgit v1.2.3