// Returns the event to be processed Event* TimeWarpReceiverQueue::getEvent(SimulationObject* object) { ASSERT(object != NULL); Event* eventToProcess = 0; eventToProcess = peekEvent(object); if(eventToProcess != 0) { const OBJECT_ID receiverId = mySimulationManager->getObjectId( eventToProcess->getReceiver() ); ReceiverQueueContainer* receiverQContainer = myReceiverQueue[receiverId.getSimulationObjectID()]; TimeWarpEventSet* receiverQ = receiverQContainer->eventSet; receiverQ->getEvent(object); schedulingData->PopHeapFlag(true); Event* nextEvent = receiverQ->peekEvent(object); if(nextEvent != 0) { //Add the current head Event into the //scheduleList receiverQContainer->headEventPtr = nextEvent; } else { receiverQContainer->headEventPtr = DummyEvent::instance(); } push_heap(schedulingData->scheduleList->begin(), schedulingData->scheduleList->end(), GreaterThan_ScheduleListContainerWithReceiverID()); } //return the event return eventToProcess; }
const Event * DefaultSchedulingManager::peekNextEvent() { TimeWarpEventSet *eventSet = mySimulationManager->getEventSetManager(); ASSERT( eventSet != 0 ); const Event *earliestEvent = 0; int simMgrId = mySimulationManager->getSimulationManagerID(); for(int i = 0; i < mySimulationManager->getNumberOfSimulationObjects(); i++) { const Event *tempEvent = eventSet->peekEvent( mySimulationManager->getObjectHandle( ObjectID(i,simMgrId) ) ); if( earliestEvent != 0 && tempEvent != 0 ) { if( tempEvent->getReceiveTime() < earliestEvent->getReceiveTime() ) { earliestEvent = tempEvent; } else if(tempEvent->getReceiveTime() == earliestEvent->getReceiveTime()) { if(tempEvent->getEventId() < earliestEvent->getEventId()) { earliestEvent = tempEvent; } } } else if( earliestEvent == 0 && tempEvent != 0 ) { earliestEvent = tempEvent; } } if( earliestEvent != 0 ) { setLastScheduledEventTime( earliestEvent->getReceiveTime() ); } else { setLastScheduledEventTime( mySimulationManager->getPositiveInfinity() ); } return earliestEvent; }
Event* TimeWarpReceiverQueue::getEvent(SimulationObject* object, const VTIME& time) { ASSERT(object != NULL); Event* eventToProcess = 0; eventToProcess = peekEvent(object, time); if(eventToProcess != 0) { const OBJECT_ID receiverId = mySimulationManager->getObjectId( eventToProcess->getReceiver() ); ReceiverQueueContainer* receiverQContainer = myReceiverQueue[receiverId.getSimulationObjectID()]; TimeWarpEventSet* receiverQ = receiverQContainer->eventSet; receiverQ->getEvent(object); Event* nextEvent = receiverQ->peekEvent(object); if(nextEvent != 0) { //Add the current head Event into the //scheduleList receiverQContainer->headEventPtr = nextEvent; } else { receiverQContainer->headEventPtr = DummyEvent::instance(); } schedulingData->MakeHeapFlag(true); } //return the event return eventToProcess; } // End of getEvent(...)